How to generate positive and negative square wave with frequency of 1Mhz?
If your transducer is a pretty ordinary piezo device then you don't need to supply it with +/-20V; a square wave of 40 Vp-p should be just fine. However, if you are unsure, then couple the output of the circuit below with an appropriately sized capacitor (a few micro farads is probably enough).

I'd be thinking about one of these just as a driver (and not part of a buck converter mentioned in the title): -



You'll have to choose MOSFETs but the LTC4444 is a pretty good driver for generating power square waves. It has sub-10 ns rise and fall times and shoot-through protection is built in. PWM inputs (aka your 1 MHz square wave) is TTL level so will work with all suitable 3.3 V and 5 V logic that generates the square wave.

As for generating the square wave, a simple relaxation oscillator built around a fast schmitt trigger will do the job (Tony shows one in his answer). Or if you want to control the amplitude of the power fed to the transducer you can vary the mark space ratio to TINP/BINP. You could use an LTC6992 for that: -