Due to the mobile and random nature of services in cyber–physical–social systems (CPSSs), developing service composition approaches that ensure high availability, minimal energy consumption, and high quality of service (QoS) remains a complex challenge. Over the last two decades, several service composition approaches have been proposed in the literature to deal with this challenge. Nevertheless, the existing approaches have certain limitations, particularly in situations where services may move from one location to another, become unavailable due to intensive battery usage, encounter failures, or undergo a decline in quality. These limitations often arise because these approaches do not simultaneously integrate mobility, energy, and QoS constraints while defining the user’s movement in a random manner. In this paper, the learning-based swarm optimization-aware service composition algorithm (LS-SCA) is proposed to overcome the aforementioned shortcoming. This approach surpasses existing ones by accounting simultaneously for the user’s mobility, energy, and QoS criteria during the service composition process. First, the Small World in Motion (SWIM) mobility model is employed in this study to determine the user’s mobility traces, avoiding the random generation of users’ traces. Second, an energy consumption model is proposed to increase the energy efficiency by avoiding the overuse of the devices’ batteries that can reduce the availability of services and lead to the composition failure. Third, the two-phase learning-based swarm optimizer (TPLSO) method is used in the composition process to find the sub-optimal composition that satisfies the global QoS constraints with the highest utility in terms of mobility, energy, and QoS. Unlike the most existing metaheuristic-based service composition approaches where the overall composition population is improved over a given number of iterations, the TPLSO method is exploited in this paper to improve only a subset of compositions, which reduces the composition time and increases the QoS utility of the composition. The simulation scenarios using two real datasets demonstrate that the LS-SCA approach outperforms six baselines in terms of energy consumption, QoS utility, and availability of composition. This notable performance makes the proposed approach more suitable for real-world applications where energy efficiency, QoS, and availability are crucial factors to consider.