We report the calculated fundamental band gaps of wurtzite ternary alloys Zn1−xMxO (M = Mg, Cd) and the band offsets of the ZnO/Zn1−xMxO heterojunctions, these II-VI materials are important for electronics and optoelectronics. Our calculation is based on density functional theory within the linear muffin-tin orbital (LMTO) approach where the modified Becke-Johnson (MBJ) semi-local exchange is used to accurately produce the band gaps, and the coherent potential approximation (CPA) is applied to deal with configurational average for the ternary alloys. The combined LMTO-MBJ-CPA approach allows one to simultaneously determine both the conduction band and valence band offsets of the heterojunctions. The calculated band gap data of the ZnO alloys scale as Eg = 3.35 + 2.33x and Eg = 3.36 − 2.33x + 1.77x2 for Zn1−xMgxO and Zn1−xCdxO, respectively, where x being the impurity concentration. These scaling as well as the composition dependent band offsets are quantitatively compared to the available experimental data. The capability of predicting the band parameters and band alignments of ZnO and its ternary alloys with the LMTO-CPA-MBJ approach indicate the promising application of this method in the design of emerging electronics and optoelectronics.