The very first question is - are the costs predictable? Can you safely say electricity is cheaper, say, 10PM to 7AM? If not, you need a communication with the utility company to assess this number.
The next question is - what is the heat loss of your house? Older houses are crap for insulation. Here in Canada, with similar issues, the first and biggest step is to properly insulate the house. do you have solid insulated doors? The old panel wood doors are not as good as solid insulation filled (metal) doors. Do you have triple-paned argon-filled window panes? (The best modern ones are as insulating as a regular wall). here in Canada, modern construction used 2x6 (inch) outer wall construction, rather than the old 2x4. The interior is also nowadays sealed with a plastic barrier to prevent air escaping. A big issue is ceilings. A common cheap upgrade for older houses is to blow up to a foot of insulation into the (unheated) attic space.
Then you can consider issues like wind and sun exposure. Adding an enclosed verandah/porch can add to the insulation value too. Older houses used to have a vestibule, so opening the outside door did not flood the whole house with cold air. Modern architecture seems to have ignored this, a byproduct of the 60’s mentality that energy was cheap and plentiful.
Another important point - how efficient are your appliances, which likely get used during peak periods. Many North American houses will have a freezer as well as a fridge. The freezer is rarely opened - but most do not have a external control to tell it - “Cool excessively during the cheap power times, so you don’t need to kick in during the daytime”. A good freezer, not opened too much, could probably go all day without need to cool - so maybe a timer that disables the freezer during the day? Also, use the microwave instead of the electric oven wherever possible, and those appliances like air fryers and induction pressure cookers, which use a lot less electricity and cook faster.
At the most extreme, is having computer controlled dampers and individual room thermostats - don’t push too much heat into a room that is not currently occupied. If you have individual room heaters, this control too is a good idea.
Tesla does make the PowerWall, which IIRC is 14kWh batteries intended to be charged by solar panels on the roof.
However, i would think any such algorithm would be heavily customized to the family’s specific needs. I would think an AI learning algorithm would work best. But - my Nest thermostat seems to have a mind of its own, doing things I don’t want it to do. (It alters the permanent schedule if I turn up the temperature too often, for example)