I have done it like this:
When USB is connected (VBUS), then the mosfet Q1 decouples the battery from the input of the regulator. The input for the regulator is then coming though diode D2. The relative large capacitor C3 ensures that there are no power glitches when USB is connected or disconnected. Resistor R4 pulls the gate of Q1 to ground when no USB is connected.
The MCU can determine the battery status through D2/D3. This lines are also interrupts, and can wake the CPU from sleep.
The regulators quiescent current is 8 uA, so that is effectively the current drawn from the battery when the mcu is in sleep. If that is to much, the regulator can be left out, and resistor R19 is placed.
Current in sleep is then 160 nA !!
And resitors R13 and R14?
These are part of the "foolproof plan"
When a user programs D2 or D3 as outputs, the resistors prevent then that D2/D3 are "hard" shortened to ground.
R2 is the charge current programming resistor.