See attached...
Hope this can solve your problem.. Its just a simple reference design..
As you can see the output is coupled to N and P Channel FET, this are just fast switching MOSFET that will switch between supplies. If theres a Power, the output voltage will came from the LM7805 which will enable the N-channel FET to produced the desire output, and when theres a no power the P-channel FET will the one to be enable to produce the desired output..
As you can see the battery charger is very simple, you can couple a battery charger circuit to enchance the charging to the battery..
Enjoy..