First-principles calculation of band offsets, optical bowings, and defects in CdS, CdSe, CdTe, and their alloys