A Reinforcement Learning Approach for Optimal Control in Microgrids