The energy spread of a beam bunch induced in a linear accelerator can be reduced to a minimum if the amplitude and the phase of the RF voltage are optimized. The energy spread is induced by the longitudinal wakefield and by the sinusoidal profile of the accelerating voltage acting on the beam. The cavity shape, the bunch profile, and the charge in the bunch determine the wake function. Aiming to have an approximately constant net voltage acting across the beam bunch, we optimize the amplitude and the phase of the RF voltage. The minimum energy spread, the required RF voltage, and the required RF phase are calculated as a function of the net charge and the length of the bunch. To find out the effect of cavity shape on the minimum energy spread, the optimization was performed for several types of cavities. 4 refs., 8 figs