Arduino Nano DC to AC

It's not quite clear if the Arduino needs to read a 40V AC or to create a 40V AC signal.

For reading 40V AC, you can rectify the AC signal (4 diodes and an electrolitic capacitor) followed by a voltage divider.

The rectifier/capacitor will create a DC voltage of roughly 56 Volt from the 40V AC and the voltage divider needs to be calculated in such a way that it reduces the DC voltage to 5V. E.g. 10kOhm from 56V to Arduino pin, 1kOhm from Arduino pin to ground.

For generating 40V AC, you will need to provide a little be more detail and it will not my area of knowledge. With the little info that you gave, if tou have a 40V AC signal available, you can switch it on/off with a relay.

PS.
I see that Chris did beat me to it. Not sure if th LM7805 is needed.
And Railroader as well.