Text this: Optimal Integration of Battery Systems in Grid-Connected Networks for Reducing Energy Losses and CO2 Emissions