  The integration of renewable energy sources (RES) into power distribution
grids poses challenges to system reliability due to the inherent uncertainty in
their power production. To address this issue, battery energy sources (BESs)
are being increasingly used as a promising solution to counter the uncertainty
associated with RES power production. During the overall system planning stage,
the optimal capacity of the BES has to be decided. In the operational phase,
policies on when to charge the BESs and when to use them to support loads must
be determined so that the BES remains within its operating range, avoiding
depletion of charge on one hand and remaining within acceptable margins of
maximum charge on the other. In this paper, a stochastic control framework is
used to determine battery capacity, for microgrids, which ensures that during
the operational phase, BESs' operating range is respected with pre-specified
high probability. We provide an explicit analytical expression of the required
BESs energy capacity for a single microgrid with RES as the main power source.
Leveraging insights from the single microgrid case, the article focuses on the
design and planning of BESs for the two-microgrid scenario. In this setting,
microgrids are allowed to share power while respecting the capacity constraints
imposed by the power lines. We characterize the optimal power transfer policy
between the microgrids and the optimal BES capacity for multiple microgrids.
This provides the BES savings arising from connecting the microgrids.
