This paper demonstrates that the incorporation of optimally-rated energy storage units and renewable generators into a remote microgrid, in conjunction with an optimal dispatching strategy, can result in substantial reduction in the microgrid lifetime cost and emission. The application of such a microgrid can be in the electrification of off-grid remote communities which, typically, heavily depend on diesel-based electric power generation. The paper presents a mathematical model and optimization algorithm to achieve the optimal microgrid configuration, in terms of the installed capacities of the generators, as well as their optimal dispatching. The results have been demonstrated for an example remote community located in the northern part of the Canadian province of Ontario.