Real-time energy management is an important challenge in today's microgrids. In this study, a two-layer technoeconomic energy management framework is proposed for an islanding microgrid. The minimisation of operation and emission costs are considered in the first layer procedure. Dynamic performance of dispatchable distributed energy resources is taken into account to improve the load following performance. Optimal operation of the microgrid is considered as an optimisation problem which is solved using modified particle swarm optimisation algorithm. In the second layer, optimal droop gains of microresources are assigned based on the combination of gradient descent method and minimum mean square frequency error algorithm. The proposed methodology is applied to a typical microgrid and its performance is evaluated. The simulation results show that using the proposed methodology, the frequency deviation of microgrid is reduced properly so that the results are better than the results of conventional methodology. Moreover, the microgrid energy management and power sharing between micro-sources are more economical in comparison with conventional methods.