Battery swapping station (BSS) is a new mode of supplying power to electric vehicles (EVs). As distributed and flexible energy storage as well as demand response (DR) sources, BSSs have great potentials to tackle both high penetration of variable renewable energy (VRE) sources and real-time EV charging. However, these potentials have not been fully explored as existing research mainly uses BSS for the single purpose of battery swapping. To make the full use of BSS, this paper presents a real-time energy management strategy for a BSS based smart community microgrid (SCMG), using VREs to supply EV batteries (EVBs) and conventional residential loads (RLs). A novel Lyapunov optimization framework based on queueing theory is designed to solve the proposed model. It addresses the variability of supply, demand and energy prices without assuming their forecasts or future distributions, and can also ensure the quality of service (QoS). The proposed method can simplify the complex energy scheduling and transform it into a single optimization problem, making it suitable for real-time applications, which require high computational efficiency. Simulation results found that BSS used for the dual purposes can improve the whole system economics and facilitate the utilization of renewable energy compared to isolated operation. It also demonstrates competency of the proposed algorithm compared to other benchmark algorithms. This work provides future SCMG operators insights into different underlying tradeoffs in managing electricity supply and demand cost-effectively with BSSs and VREs.