I need help on how I would go about solving this problem, my apologies for the vague title
I agree that it looks like an optimization problem, but the parameters are not completely clear. Here are some vague ideas I have about the design of such a system:

Let's assume a unit of time for which you have data and by which you attempt to predict things, for instance by the hour.
I think the first part needs to be about predicting energy needs by unit of time, based on past data and using any relevant factors as features (e.g. temperature, week day or not, etc.). I think this would be a reasonably standard time series regression problem.
The second part would be the optimization of energy consumption or carbon footprint: assuming we know the energy needs for a given period of time by unit of time, what are the optimal times for storing/discharging the battery? I don't know enough about the technical factors here, but I guess it's possible to simulate the target (say carbon footprint) based on different scenarios, and then select the optimal scenario. It seems to me that the problem at this stage could be simple enough to simulate all the scenarios and find the exact optimal times, that would probably correspond to a grid search. but in case this is too complex there are ML techniques which could estimate them, for instance genetic algorithms.