How do border formalities work? Where will passports and visa be checked?
You will get your passport checked twice - once in Hung Hom Station in Hong Kong, where the Hong Kong Immigration Department will conduct the exit checks, and once in Guangzhoudong (Guangzhou East) station, where the Chinese Immigration will conduct the entry checks.
This is mentioned on this webpage (translation mine):
(Immigration checks are conducted in the origin and destination station separately)
Curiously, the English version suggested it is done in either station:
Immigration formalities are conducted at the departure or arrival station.
I will stick with the Chinese version.
How much time to I have to reserve in order to catch a connecting train from Guangzhou safely?
The link you have provided (30-40 mins) is a reasonable comparison. Usually it will be slightly quicker as intercity trains are sparse (as compared to the port in Lo Wu, which is connected by at least 12 commuter/metro trains per hour, 18 in peak hours), and are not usually full, which means less fellow passengers competing to get through.
As an aside, you are also advised to arrive at Hung Hom Station 45 minutes before the train departs according to MTR's (the operating company) website:
Passengers are advised to arrive at Hung Hom Station 45 minutes before the scheduled departure time for exit formalities. The boarding gate will be closed 10 minutes before the train departs.