It's a very reasonable plan, well-laid out. Thoughts:
a) On the 21st, you might want to consider a taxi vs a public bus from Tunxi to Tangkou, especially if it will allow you to get to Tangkou by 08:00-08:30. If you are walking up, at least you won't have a cable car queue wait.
b) I recommend departing Beijing on the 27th by first morning high speed train to Pingyao, and would definitely spend all day and overnight there as well.
c) On the 28th, I'd put another day in the Pingyao area and go to nearby places such as Wang Family Mansion, maybe Mianshan and Zhangbi Underground. Another overnight in Pingyao.
d) 29th take first morning high speed train to Xi'an, rest of day there. Also the 30th and 31st. Fly to Guilin late afternoon/evening of the 31st and overnight there.
e) If you are cutting the Rice Terraces due to arriving after the harvest (IMO a reasonable thing to do), then I think you can cut a day out of the Guilin area and move your arrival to evening of the 31st and spend night in Guilin. This leaves you with full days the 1st, 2nd, 3rd, and part of the 4th to explore the area. After the first night in Guilin, I'd get moving to the Yangshuo area next morning and set up your base of operations there, including any boating or rafting on the rivers that you might want to do.
f) End plan is fine to put your last couple of nights and a free day in Shanghai.
One thing you might consider on either the front or back end of the trip, is a half-day to visit a water town near Shanghai, maybe Zhujiajiao.