Optimal transcriptional regulation of cellular responses to sudden environmental shifts