It's called a buck-boost regulator, or a flyback regulator, or a SEPIC converter. Unless you have the know-how (and space and time) to build one from scratch, it's easiest just to buy an IC and wire it up to the necessary inductors, resistors, and capacitors.
WHat type of AA batteries? NiCd? NiMH? It makes a difference. That may be why you should just fine a battery charging IC that should generate the proper voltage for you, as well as monitoring the cut off and everything like that.
Huh? Do you mean a steady 5V voltage with a maximum amp draw of 500mA?