Optimal control of nonregular dynamics in a Duffing oscillator