This paper proposes an Internet-of-Things (IoT) based energy management system (EMS) for the optimal operation of unbalanced three-phase AC microgrids. The system utilizes a software architecture based on microservices, which includes a stochastic economic dispatch optimizer (EDO), a database, a web-based graphical user interface (GUI), and an application programming interface (API). The EDO uses a mixed-integer linear programming (MILP) model to ensure the day-ahead dispatch of the distributed energy resources (DERs) in the microgrid while adhering to grid constraints such as voltage, current, and power limits. Additionally, the optimization module takes into account security constraints for unplanned islanded operation, as well as stochastic scenarios of local demand and renewable generation. To assess the performance of the proposed IoT-based EMS, tests are conducted using a real-time simulator in a software-in-the-loop (SIL) experimental setup. Actual data from a microgrid located at the State University of Campinas (UNICAMP) in Brazil is utilized for the tests. The microgrid consisted of a photovoltaic (PV) system, a battery energy storage system (BESS), a thermal generation unit, and variable demands. Results indicated the effectiveness of the proposed IoT-based EMS in monitoring the operation of the microgrid and defining the optimal day-ahead dispatch of local DERs.