With the rapid popularization of EVs (Electric vehicles), the uncoordinated charging and swapping behavior of residential EVs may increase more power load during the peak period of the original urban power grid, affecting the stability of the power grid. Therefore, based on the high potential for scheduling the charging and discharging operations of EVs and batteries of battery swapping stations in residential quarters, this paper proposes an optimal dispatch strategy for urban residential quarters considering nearby battery swapping stations. First, the paper establishes a two-stage optimal electricity dispatch model that takes models of residential PV, the V2G (vehicle to grid) function of EVs, and the nearby battery swapping station into account. Second, to compare the total electricity cost and peak-valley difference before and after optimization, the paper also establishes a model for simulating uncoordinated charging and provides evaluation indices for comparison. Finally, based on specific data from a residential quarter in Shanghai and a nearby NIO battery swapping station, the effectiveness of the optimal electricity dispatch strategy is verified, and a specific scheduling plan is provided.