An exactly solvable model of a stochastic heat engine: optimization of power, power fluctuations and efficiency