Previously, the authors have proposed a novel combustion control enabled by the free piston engine (FPE), e.g. the piston trajectory-based HCCI combustion control. Extensive simulation results show that, by employing specific piston trajectories, the FPE is able to increase the engine thermal efficiency significantly, and reduces the emissions production simultaneously. However, a systematic approach to designing the optimal piston trajectory, according to variable working conditions and versatile fuel properties, still remains elusive. In this paper, the study of this optimization is presented. First, a control-oriented model, which includes thermodynamics of the in-cylinder gas and chemical kinetics of the utilized fuel, is adapted for the optimization study. The unique phase separation method was also implemented into the presented model to sustain sufficient chemical kinetics information and reduce the computational burden at the same time. Two optimization methods are then proposed in this paper: one is converting the original problem to parameters optimization; the other is transforming it to a constrained nonlinear programming and solving it via the sequential quadratic programming (SQP) method. The corresponding optimization results and detailed discussions are followed, which clearly demonstrate the advantage of the trajectory-based HCCI combustion with regard to FPE output work and NOx emission.