A microgrid is a flexible and localized grid that can disconnect from the main grid and operate independently on the traditional and/or renewable resource. It also can work with the main grid, and even provide power to the main grid when it has excess power to help relieve the pressure of energy. The flow of power between main grid and microgrid is monitored by smart meter, which kept the end user’s privacy information and his/her energy usage in real time. Hence, ensuring the privacy and security of these information is a considerable challenge. In this paper, we investigate the relationship between microgrids and the main grid, and design a quantum-resistant lightweight authentication and key agreement (AKA) protocol based on fog computing. The proposed protocol provides the mutual authentication and generates a session key between a smart meter and a fog node. More importantly, it can resist against quantum computing attacks, as the security of our scheme relies on the hardness of the learning parity with noise (LPN) problem, an NP-complete problem. Finally, we evaluate the performance of our proposed protocol and prove that our protocol is more lightweight and efficient.