The aim of this paper is to study the optimization of the rail profile for heavy haul railways. A numerical model is developed, where the rail profile is parameterized as a generalized function for a series of independent variables. A well-designed formula, which characterizes the conformance between wheel and rail profiles around contact point for all possible wheel–rail contact situations, is considered as the objective function. During the construction of the objective function, a wheel–rail contact geometry algorithm is implemented to detect contact point positions quickly. Linear and nonlinear constraints are introduced in order to meet some necessary conditions. Then, the optimization of rail profile can be transformed into a typical mathematical nonlinear optimization problem with single objective, multivariables, and multiconstraints. In order to solve this problem effectively and efficiently, the sequential quadratic programming algorithm combined with Lagrange function, quasi-Newton method is employed. At each major iteration, a quasi-Newton approximation is made of the Hessian matrix of the Lagrangian function using BFGS updating method. This is then used to generate a quadratic programming subproblem whose solution is for forming the search direction for the iteration of independent variables. Finally, the R75 rail profile, prevalently used in China’s heavy haul railways, is optimized using the developed model to better match the LM wheel profile. A modified rail profile is put forward and compared with the original rail profile systematically in wheel–rail contact geometry relationship, vehicle–track dynamic behaviors, and wear developments. A vehicle–track coupling dynamics model and a wheel–rail wear prediction model are respectively established to conduct the comparative study. According to the calculation results, the optimized rail profile is proved to have superior performances and, thus, can be considered a better choice to match LM wheel for China’s heavy haul railways, which is of practical value for the design and preventive grinding of heavy haul rails. In addition, this application example validates the rationality of the developed numerical optimization model. It can also be used for the optimization of other rail profiles.