Switching between AC and DC input
The wizardry lies in using diodes in series to be able to put DC power supplies in parallel without damaging them from (even tiny) differences in voltage, just like on the following diagram. 

Then from there, you can replace the second power supply by a rectifier which converts AC (of appropriate voltage amplitude, use transformers upstream if not the case - or DC/DC converters downstream) to DC. Note that in this setup, D2 wouldn't be necessary as the rectifier already prevents current from going upstream.



For the explanation, diodes are analog OR gates: whichever has the higher applied voltage puts the diode in conduction, and the other prevents current from going in the other power supply. 

Warning: for this to work, at least one of the power supplies needs to have a floating ground (be isolated from eachother) or have the exact same ground, otherwise they're going to force eachother to different potentials and result in shortcircuits.

Finally, you may want to place a voltage regulator after the two power supplies because of the rectifier (which would allow you to place the battery straightaway as PS1).

However, why not use mains-DC adapters that lie around to take care of the AC/DC conversion, and just make sure your battery + regulator and that adapter are put in parallel with diodes?