This code shows how to use the deepsleep function to save energy for phases where you don't need to be connected. The sketch sends temperature and humidity every 10 minutes to thingspeak and hibernates in between. An ESP8266 testboard has been already running for more than 2 months on 3 AA batteries alone.
See