I believe the answer lies in calling "system_deep_sleep()". This takes a parameter of the number of microseconds to sleep for. When called, the device will all but power itself down and when the interval duration has passed, it will wake up and start again. I believe some small amount of non volatile RAM may remain refreshed so you can remember some state on wake up.
I also believe that there may be a way to specify an alternate wake up mechanism beyond just an interval timer using a GPIO pin signal change. This may work in conjunction with the deep sleep timer ... so the device will wake up again either because of a timeout of the interval or as a result of a GPIO signal change.
All in all, the core function is "system_deep_sleep()".
See also: