In this paper, a two-stage optimization strategy for designing defective unit cells of phononic crystal (PnC) to explore the localization and waveguide states for target frequencies is proposed. In the optimization model, the PnC microstructures are parametrically described by a series of hyperelliptic curves, and the optimal designs can be obtained by systematically changing the designable parameters of hyperellipse. The optimization contains two individual processes. We obtain the configurations of a perfect unit cell for different orders of band gap maximization. Subsequently, by taking advantage of the supercell technique, the defective unit cells are designed based on the unit cell configuration for different orders of band gap maximization. The finite element models show the localization and waveguide phenomenon for target frequencies and validate the effectiveness of the optimal designs numerically.