Over the years, a range of Internet of Vehicles services has emerged, along with improved quality parameters. However, the field still faces several limitations, including resource constraints and the time response requirement. This paper extracts cost, energy, processing power, service management, and resource allocation parameters. Mathematical equations are then defined based on these parameters. To simplify the process complexity and ensure scalability, we propose an algorithm that uses the genetic algorithm for fault and cost management during resource allocation to services. The main concept is to pick resources for services using a genetic algorithm. We discuss the processing and energy costs associated with this function, which is the algorithm's objective function and is created to optimize cost. Our approach goes beyond the conventional genetic algorithm in two stages. In the first step, services are prioritized, and resources are allocated in accordance with those priorities; in the second step, load balancing in message transmission paths is ensured, and message failures are avoided. The algorithm's performance is evaluated using various parameters, and it was shown to outperform other metaheuristic algorithms like the classic genetic algorithm, particle swarm, and mathematical models. Different scenarios with various nodes and service variables are defined in various system states, including fault occurrences to various percentages of 10, 20, and 30. To compare methods, we consider different parameters, the most significant being performance success rate. Moreover, the cost optimization has a good convergence after iterations, and the rate of improvement in the big scenario has slowed down after 150 iterations. Besides, it provides acceptable performance in response time for services.