You didn’t say how much you want to spend or your space limitations, power supply info etc.
If this were me, I would buy a cheap ESP32 with a LIPO charger built in. I would disable the WiFi, since you don’t need that for the ESP32. You just need the controller part with the auto recharging of a LIPO battery. The ESP32 watches for a periodic signal from the IMP (imp output pin to ESP32 input pin) Pin voltages between imp and esp32 are both 3.3V.
If the pulse is not detected, the esp32 drops a relay or whatever to kill power to everything, including itself. But it continues to run on the LIPO. After a minute it restores power.
The nice thing about this is when there is a “brown-out” or flicker of main power, the esp32 can turn everything off (as it can also monitor input power) and keep things off for a couple of minutes. A two minute power outage is way better than a 0.5 second power flicker or brownout.
Cost for esp32 w/LIPO charger, the LIPO battery, and some sort of relay or something to cycle main power … probably $50? esp32 programming using arduino IDE (which is free).
I mention the esp32 only because it’s a really cheap controller with LIPO charger. Not all controllers come with a built-in LIPO charger as its backup power.
That’s my 2 cents on this.
Added bonus is you could enable the esp32 wifi and use it for monitoring, but no need to have that extra wifi signal interfering with the imp’s wifi. Disable the esp32 wifi (and bluetooth).