A self-propelled flexible fin with heaving and pitching motions in a quiescent flow has been simulated by using the penalty immersed boundary method. The flexible fin can move freely in the horizontal direction and the body of the flexible fin moves passively along with the active head motion. The position of the head of the fin was described as a harmonic heaving oscillation in the vertical direction, while the inclination angle of the head was prescribed as a harmonic oscillation with a moving clamped condition for the heaving and pitching fin. The cruising speed and the swimming efficiency of the self-propelled fin were determined as functions of the bending stiffness (γ), the heaving amplitude (Ah), the pitching amplitude (Ap), the flapping frequency (f) and the phase difference (Δϕ) between Ah and Ap. We optimized the cruising speed and the swimming efficiency with respect to γ, f, Ah, Ap and Δϕ. For a certain range of Ap, the swimming efficiency of the heaving and pitching fin is larger than that of a heaving-only fin.