......................D1.....................
VCC (5V) ------>|--------------+-----|uC|
............................................|
............................................|
...............Vbat (4.5V)....D2....|
..........................-------->|---+
..........................|
.......................__|__+
........................___ ...... 1,5V battery cell
..........................|
.......................__|__+
........................___ ...... 1,5V battery cell
..........................|
.......................__|__+
........................___ ...... 1,5V battery cell
..........................|
.........................gnd
Use Schottky diodes
When VCC is on D1 conducts and no current runs from the battery because of the lower battery voltage (4,5V).
When VCC is off the voltage between D1 and D2 drops to 4,5V - Vf(D2), then the battery starts to conduct.