Consider the train as the frame of reference, initially not moving, and the tennis ball travelling toward it at 40mph. In a perfect elastic collision, we need to conserve both momentum and kinetic energy. That means that if the speed of the ball is s and the speed of the train is S, and the mass of each is m and M respectively, and we denote final speeds by s' an S',

s'm + S'M = -40m

S' = -(40m-s'm)/M

If we assume that the ball's mass is negligible compared to the train, then this is very close to zero, and the train is propelled imperceptibly slowly in the negative direction. In order to preserve kinetic energy, then the ball has the same speed with respect to the train as it did before, 40mph.

Then the answer is that the ball's final velocity relative to the ground is 70mph.

EDIT: Just realized the answer was already provided above.