I have a friend who fasted for 40 days.

Yes, it is true. he lives nearby. On the last day of fasting he was a dead man walking. His mind was as clear and sharp as ever, but his body was weak and dying. he was walking and talking slowly like he had no energy. Then, when he started eating, his body rejected food. It took a whole week for his body to start receiving food without throwing up. So, it's actually been more than 40 days, since he threw up everything he ate within seconds.

He didn't eat anything, just drank lots of water. I've talked to him once about it and he said that fasting for so long can be very dangerous, and one should better really know what he's doing or have someone else (who knows what he's doing) guide him. You have to know what to do and not to do, how to keep your body healthy and mind clear.

Although you can't fast that long, and I know little about it, I can recommend 4 things:
1. Like oskee said, work your way up to it. This friend of mine was preparing himself for this, and it's his third fasting for long period of time. Besides, few days every month he's fasting. Spending a day without eating is completely normal to him.
2. Drink plenty of fresh water.
3. After done fasting, start with easy foods, like for really small babies, until your body adjusts to food again.
4. Eat healthy. Strictly vegetenarian, not even eggs.

His motives were self-growth, religious.

He told me about one ocurrence, which I found very interesting. After some time of fasting (I think it was 10 days or two weeks, not sure which) he was able to see things he wouldn't normally see. For example, if he played cards he would "see" every card his opponents had. Just like that. So, yes, fasting does clear mind. Mind and body are more connected than we think.