This paper proposed an improved particle swarm optimization (PSO) algorithm for the variable parameter power difference charging and discharging strategy of battery energy storage system (BESS). The charge and discharge power of the BESS under different load intervals and state of charge (SOC) intervals are distributed, and the objective functions of peak shaving and valley filling standard deviation and minimum SOC off-line rate are established. The simulation model of peak shaving and valley filling is built, and the results show that the standard deviation of peak shaving and valley filling reduced by 22.58% compared with PSO. The effectiveness and feasibility of the improved PSO are verified.