This sounds like perfect use case for a backup-battery, if the power is going out (or fluctuating enough to turn it off) a backup-battery would smooth that out and allow your computer to stay on assuming there's enough power to charge the battery in the first place. Reducing your computers power consumption could help but it depends on what your hardware is, and what kind of load your computer operates at even while "idle".