The ball will bounce back, relative to the train, with a velocity of 40 m/s. Since the train is going at 30 m/s relative to the ground, then the ball is going at 70 m/s relative to the ground.

I described it to myself as:In the train's reference frame, the ball is approaching the stationary train at 40 m/s. Since it is a perfect elastic collision, the ball rebounds off the train, now moving at 40 m/s in the opposite direction.

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.