This is a very simple task which will enable wifi on a set interval and check for known wireless networks. If a network is found, wifi will remain on. If no network is found, then wifi turns off.
To set this up on your android phone, follow these steps:
1) Create new profile
2) First Context: Time
3) Check "Repeat" and uncheck "From" and "To". I do 5 minutes, but set the interval to whatever you want. Click "Done"
4) New Task
5) Set Wifi On, If %WIFI ~ off
6) Wait 30 seconds, If %WIFII !~ *CONNECTION*
7) Set Wifi Off, If %WIFII !~ *CONNECTION*
8) Click "Done"
9) Click "Apply"
Now your phone will automatically connect to networks it remembers, but will also turn wifi off to save battery when not connected.