This paper presents the economic analysis and optimal energy management of a grid-connected MG that comprises renewable energy resources and different battery storage technologies with different characteristics such as initial charge, depth of discharge, and the number of charging/discharging cycles to minimize the total operating cost of the system by maximizing the benefits of BSS, minimizing the investment and replacement cost of BSS, and minimizing the operation and maintenance cost of DGs. Several constraints are considered, such as the output power limits of the distributed generators, the limits of power imported from or exported to the grid, load balance, and other sets of battery storage constraints. The general algebraic modeling system (GAMS) is used to solve the deterministic optimization problem. Second, stochastic optimization is used to solve the deterministic problem with market price uncertainty. Third, robust optimization using the information gap decision theory is presented to model the electric load uncertainty. The validity and effectiveness of the proposed solution are explained by comparing the results obtained by GAMS to the results obtained by other optimization techniques presented in the literature.