So my question is, can I make the distance measurement calculation function work in the background
Sure, as soon as you install an operating system, so that "in the background" means something.
The Arduino doesn't have an OS, so there is no "background" process that can do anything.
What is the purpose of the menu? A range finder measures distances. I can't see how you need a menu for that.