A hierarchical control scheme is defined for the energy management of a battery energy storage system which is integrated in a low-voltage distribution grid with residential customers and photovoltaic installations. The scope is the economic optimisation of the integrated system by employing predictive control techniques. The approach is based on hierarchical decomposition of the optimisation problem in the time domain by composing a three-level scheduling and control scheme, that is, day-ahead, intra-hour, and real-time, where the initial and final states of each sub-problem are chosen as coordination parameters. The day-ahead and the intra-hour problems address the interactions with electricity markets during the scheduling phase. The real-time algorithm is able to adapt the operation of the battery system according to updated information about market conditions, residential demand, and local generation, and subject to the network capacity and other technical constraints. The simulation scenarios address the interactions with the day-ahead auction and the imbalance settlement system in the Netherlands.