How does the primary and secondary voltage of a transformer be in the opposite phase in the vector diagram?
The primary and secondary induced voltages (E1 and E2) are in phase as shown. However they are 180 deg out of phase with the primary applied terminal voltage (V1). 

Using -E1 just makes it easier to draw the phasor diagram.