I dislike Emei Shan so I'm not the best authority on that, keep it as you have it. I love Dazu but Chongqing has always rubbed me the wrong way (though plenty of people are OK with it). I do think that taking Dazu/Chongqing out of the mix will give this itinerary better "breathing room." By taking a morning flight Chengdu-Xi'an on the 13th, you pick up a day. Give yourself the rest of the 13th and part of the 15th for Xi'an with Huashan on the 14th. On 15th, take afternoon 16:00 fast train Xi'an to Pingyao. Overnight 15th and 16th in Pingyao so you'll have full 16th there. 17th the easiest way to go Pingyao-Datong is taking the standard train 07:28-15:27. This wouldn't leave you with a lot of time to see anything except maybe one of the city temples. But the entire next day 18th is enough to do Yungang and Hanging Monastery and some miscellaneous. Consider taking the night flight DAT-NAY (Beijing Nanyuan Airport). So you get to Beijing for overnight on the 18th and have the full next day for sightseeing.
Another option that might be easier to execute, would be to substitute Luoyang for Datong (Longmen Grottoes instead of Yungang Grottoes) and then do Pingyao-Beijing directly by fast train. Doing this, you'd keep Dazu/Chongqing in the mix on the 13th but take night flight Chongqing-Luoyang (Spring Airlines) and spend night there. 14th at Luoyang and another night there. 15th do the first fast train to Huashan (leave stuff at rail station or Visitor Center) then all day there then late afternoon/evening fast train to Xi'an. Xi'an on the 16th and most of the 17th, with afternoon fast train to Pingyao. Evening of 17th and most of day 18th in Pingyao. Late afternoon fast train on 18th Pingyao to Beijing.
Don't cut anything out of Beijing, and try to get there by night of the 18th if possible so you have 4 full days.