OPTIMIZATION OF SWITCHING CONTROL AND MICROGRID ENERGY MANAGEMENT