Optimizing battery use to minimize emissions is possible, but generally overly expensive.
A recent study of residential home batteries that are AC coupled (such as Enphase and Tesla to name a few), as contrasted to the DC coupled residential home batteries (such as SolarEdge SolarStore inverters for example) points out the fact how a battery system is charged relates to the effect on overall emissions. If the battery is only discharged during periods of peak emissions and only charged when fossil fuel use is low, then a household might reduce emissions.
See the full report at: https://arstechnica.com/science/2018/12/residential-batteries-may-save-households-money-but-rarely-reduce-emissions/