The advancement of virtual coupling technology in urban rail transit has facilitated the online coupling and decoupling of trains, enabling a range of flexible transportation configurations, including various route types and adjustable formations. This study targets the fluctuating passenger demands on urban rail lines, aiming to minimize both passenger travel and operational costs. The model integrates constraints associated with virtual coupling, train operations, rolling stock circulation, and the interaction between virtually coupled trains and passenger arrivals. New decision variables are introduced to depict the train formation state under virtual coupling scenarios. An integrated optimization model for train diagrams and rolling stock circulation under virtual coupling conditions is developed, employing a genetic-simulated annealing algorithm informed by train operation simulations. A case study on an urban rail line during the morning peak examines the optimization of train diagrams for full-length and short-turn routes. Findings confirm that virtual coupling technology effectively adapts to lines with uneven passenger flow distribution, significantly enhancing the match between supply and demand, equalizing spatial and temporal traffic variations, and harmonizing the quality of passenger services with operational efficiency.