If it is just as a signal...Amplify it and then chop off the top and bottom of the waveform with zenners (crude dirty way) Or slap it into an op amp with some positive feed back, again you will have to limit the excursion of the wave form.
If it's for power....why?
__________________
health warning: These posts may contain traces of nut.
If it's a low-level signal, use an optocoupler with current limiting on input circuit (40 V / 20 mA = 2000 Ohms), which won't give you exactly a square wave, but the transistor output will either be "off " or "on." If you need a square wave, the full-wave rectify the input sine wave and alternate between "on" and "off " with a flip-flop.
'Course, all bets are off if it's for power -- that's a different animal.
__________________
We have met the enemy and he is us . . . Walt Kelly
If you Wiki Furrier transformer (just for the hell of it) It comes up with Tom and Jerry
__________________
"Multa ferunt anni venientes commoda secum, Multa recedente adimiunt". (The years as they come bring many agreeable things with them; As they go they take many away).
you can use a simple comparetoor, such as lm324, lm 339 etc.
one input set at 20DC, another inport termianl your signal, the output will be square wave.