This paper concerns the development of a cost-effective approach to deploy the flexibility that electrical battery storage can offer to support the secure operation of medium voltage electrical networks under varying operating conditions. To this aim, and unlike related studies of the current state-of-the-art, the approach presented in this paper is based on a multiperiod optimization model that simulates half-hourly operational decisions. The optimization model includes a non-linear power flow equation based representation of the system, branch capacity constraints (instead of energy flows-the traditional state-of-the-art practice), different feasible battery sizes (currently available in the market), high RES penetration levels, the time of use electricity prices (half-hour dynamic prices), load data of customers (defined from real-world profiles), and reference battery costs (from existing literature). The objective is to decide the location and size of the battery storage within the medium voltage electrical network by minimizing the difference between operational and capital expenditures. The location of the battery storage is modeled with binary variables, whereas the size is modeled as a parameter first and then as a continuous variable. The value of the optimization model is demonstrated in a case study built upon a modified version of the IEEE 33 bus test system.