Optimal binning of X-ray spectra and response matrix design