A Metaheuristic Algorithm for Flexible Energy Storage Management in Residential Electricity Distribution Grids