How to select power (between USB and battery)?
You can use a load sharing circuit like this one:



When no USB is connected, the PMOS transistor Q1 will be on (through the pull-down resistor R2) and the battery will power your circuit. When the USB is connected, the input voltage will bring the gate of Q1 up disconnecting it, and the MCP73831 will be charging the battery, while at the same time the usb will be providing power to your load through the D1 diode.
You can use any battery charger chip (this one is very simple), but the principle and load sharing circuit can be the same.