Energy storage systems have a key role to play in increasing the uptake of distributed renewable energy generation. In many places, reduced feed-in tariffs and declining solar incentives are making behind-the-meter energy storage a favourable option for many distributed generation owners. Parts of the grid that have sufficient local generation can be operated as microgrids. In most cases, the temporal profiles of demand and generation do not align well, making energy storage design a critical step in proper microgrid design. Moreover, significant economic and operational benefits can be achieved by appropriately sizing and operating energy storage systems in microgrids. In this work we provide a framework that can be used for the sizing, positioning and operation of batteries in ways that both reduce the cost of operating a master-slave microgrid while also maintaining a high quality of service for the network. We formulate a mixed integer linear program based optimization algorithm that considers various operational and capital costs, as well as relevant network-related constraints. The performance of our algorithm is validated using a case-study simulation.