This sounds like a router DNS pass through problem or a DNS server problem. Router DNS problems can occur through router firmware bugs or by lossing requests due to a too heavy traffic volume problem on the router.
Check for a firmware update from the manufacturer your router on their support web page.
I had a very similar problem on my 3GS. I think I've now solved my problem.
Try the following:
Goto Settings->General->Reset and then choose "Network settings". After that, all saved Wifi settings will be deleted and the Phone/Pad reboots.
After I did that, my wifi worked stable again (for about 24h now).