MHz Speed Analog Reading + High Quality 40kHz Square Wave

10kHz is the limit with the Arduino unless you want to go off-piste, when higher speeds with lower resolutions are possible.
Comparators and zero-crossing detectors can be useful techniques for higher resolution ultrasonics, as can external high speed clocks.

Perhaps you should rethink your thread title?