Easy access to renewable energy sources (RESs) without geographic restrictions, their availability and free, and most importantly the reduction of environmental and security problems, leads energy producers to replace these sources. For this reason, microgrids and nanogrids are expanding rapidly and form the future of power grids. Therefore, their study and investigation is of particular importance. The purpose of this article is planning for optimal energy operation in DC microgrids in order to reduce costs. Also, in order to be able to dispatch RESs, hydro-pumped storage and battery and DRP have been used. Uncertainties have been modeled using the scenario method. It is a probabilistic and non-linear problem which is modeled in GAMS software and solved with CONOPT solver.