retain values after power down

Use the EEPROM.
Be aware that EEPROM has limited erase/write cycles, so only write values a few seconds after they have last changed.