Ive had a similar problem, at times the wifi button will be completely greyed out so i would have to reset my iphone holding the power and home button, at other times it would search and never find the wifi even when literally placed on the router.
When it did find my router it either wouldnt connect or connect for 10 seconds and switch back off, after trying everything from fully restoring my phone and loosing nearly everything, i even seen a video of people putting their phones in the freezer for 45 mins which for some it worked but unfortunately not for me, then i tried to downgrade my ios software to 5.1.1 because everyone was saying the new ios was causing the problem.
Eventually after three days of searching online for answers i seen one about resetting your network setting, this is the one that working for me i just had to find my wifi which it did straight away and retype the passcode.
Seems like a simple solution apart from the fact i lost nearly all my files restoring it,
hope this works for everyone or helps atleast.