Battery and dc input
The best way is to use a battery charger IC with "power path management".  Without more information on your battery chemistry, desired charge rate, system current requirement, etc. it's impossible to recommend a specific device, but here's an example: TI Charger with power path

You will need a boost converter to boost the battery or system voltage output up to 5V.