Optimization Of Battery Energy Storage System Operation In Distribution Grids