An Optimal Control of Distributed Energy Resources to Improve the Power Quality and to Reduce Energy Costs of a Hybrid AC-DC Microgrid