Any Arduino or PIC microcontroller can do what you want, and can run on a 4 rechargeable AA batteries (4x1.3v max = 5.2v) for months. Technically, they could run on a 3v CR2032 battery but the relay needs a lot of current to switch states so a single coin cell battery would not do.
Configured at 1-4 Mhz, such a microcontroller will use mA worth of current, very little.
You can use ADC or i2c or whatever to monitor the change in magnetic field at the window (when window opens, magnet on window moves away from sensor so the reading changes and the microcontroller reads that change and does the job)
You can use a 5v bi-stable relay to do the job, and you can power it directly from batteries. You switch states by sending 5v through a relay pin for a few seconds
Here's an example of 5v dual latching relay :
https://www.digikey.com/product-detail/en/omron-electronics-inc-emc-div/G5RL-K1-E-DC5/Z4395-ND/4947136Send 5v for more than 30ms and it switches on and then uses no power to remain on.
Send 5v for more than 30ms on another pin and it resets.