Continuous voltage on IO Pins while 5V is not Connected?
For this I would recommend isolating the power from the batteries with P-channel MOSFETs and only switching them on when you want to sample the voltage. This means that there is no power consumption at all (aside from an absolutely minuscule leakage current) when turned off.
The whole setup would require 4 MOSFETs - two P-channel and two N-channel. They don't need to be big, since the currents involved are very small, but they do need to have &quot;logic level&quot; thresholds, ideally &lt; 1.5V (-1.5V for the P-channel).
The basic circuit looks like this:



simulate this circuit &ndash; Schematic created using CircuitLab
The circuit is made up of two identical segments - M1+M3 and M2+M4.  The operation is fairly straightforward:

M1 (M2) is kept in the OFF state by R1 (R2) pulling the gate up to source.
M3 (M4) can pull the gate of M1 (M2) LOW turning it on and allowing current to flow
Any GPIO pin (D7 in this example) can control both M3 and M4 together
R5 keeps M3 (M4) off when there is no power - otherwise it floats.
R3/R4 are your existing voltage divider.

The purpose of M3 and M4 is to both turn the GPIO (D7) into &quot;open drain&quot; so that it's either pulling down or floating high (rather than driving high at 5V) and to isolate the two pullup gate voltages. The same effect could be achieved by two diodes and one MOSFET but it's simpler to just use two MOSFETs and not have to get diodes as well.