Recently, economic and environmental problems have created a strong attitude toward utilizing renewable energy sources (RESs). Nevertheless, uncertainty of wind and solar power leads to a more complicated energy management (EM) of RESs in microgrids. This paper models and solves the EM problem of microgrid from the generation point of view. To do this, mathematical formulation of a grid- connected microgrid including wind turbine (WT), photovoltaic (PV), micro turbine (MT), fuel cell (FC) and energy storage system (ESS) is presented. Furthermore an improved incentive-based demand response program (DRP) is applied in microgrid EM problem to flatten the load pattern. Comprehensive studying of EM in both intra-day and day-ahead markets is another contribution of this paper. However, the main novelty of this paper is proposing a new uncertainty modeling technique which is based on copula function and scenario generation. This paper tries to optimize operational cost and environmental pollution as the objective functions and solve them using group search optimization (GSO) algorithm. Numerical results approve the efficiency of the proposed method in solving microgrid EM problem.