I call this "Open World" versus "Story Arc." Obviously both styles are fine but I've seen this problem as well. The sides get a little tired of each other.
If you want to bring your wanderers into the story I suggest you tie some plot points to their characters' history. Or rather, add their history to the plot points.
Examples are to add in mid-crawl bosses that insulted/betrayed them earlier. Or scour their backstories for ideas. Did they know their uncle was a necromancer? That he stole your grandfather's shield from your father? That sort of thing.
The other way I handle this is by using the open-world players to advance the story. I've always felt these folks need to know the whole world is lush and interactive.
So, if they drop the quest to find the dragon's lair to get into the slave trade they'll naturally meet someone that begs for freedom in exchange for showing them a vast treasure. Guess where that treasure is?
Look, people are of course going to get wise to this sort of thing but we all have a tendency to like stories that tie together. Some folks just don't want to follow what feels like a paved road.
Your players are invested in a different game.
The first group that I played with played the way you describe: mucking around town, not caring much about objectives, messing with every NPC they meet. It took us entire sessions to get through even the most basic of quest-giver scenes, and we delighted in spiking plot hooks and keeping the DM on his toes. I still play with that group, and it's still a lot of fun!
It is likely that your players have a very different view of the gaming experience--maybe socializing or being "off-task" is just a form of relaxation. While you may want to push through the prewritten campaign, maybe they want to just blow off steam and mess around in a fantasy world, doing things they'd never do in real life. Both viewpoints are perfectly valid ways of approaching a TTRPG.
On the other hand, the group I DM for is very plot-oriented---they will eat up quest hooks, and they will efficiently pursue their goals. When I first DMed for them, I was surprised that they completed a quest in the time it took my other group to stroll through town.
Adapt or pass the baton
Trying to force those players into "focusing" on the game will likely just swap your roles: you might be satisfied, but your players might chafe against your "railroading". The first DM of my first group tried to do this, and it caused a lot of friction in the group. Eventually, that DM became a player, and we had a different DM. This DM, instead of trying to run a coherent plot, simply had an omnipotent, insane NPC wizard teleport us around and told us to cause chaos. As you might imagine, this went over a lot better.
Additionally, instead of making deep dungeons or storylines, he focused on making more interesting NPCs and environments instead. This NPC focus meant that he was prepared to create interesting scenarios when we were messing around in town, and he didn't waste time on dungeons we would never enter. For example, in your tavern, you can have a champion or something challenge the PCs to a 1:1 fight, or give the shopkeep a interesting prank magic item (horn of baubles, maybe?). If your players like wandering off or doing individual things, plan more individual encounters or ones that don't require the whole party to be present. I realize you're trying to run a published adventure, but maybe that's not suitable for this group. You will probably get more mileage out of the adventure by using its encounters and NPCs as inspirations for your own modified campaign, rather than running it straight.
Basically, the three questions you ask at the end are basically, "how can I force my players to play how I want?" Instead, you should be asking, "how can I adapt my campaign for these players?" If the answer to that latter question makes you not want to be a DM anymore, then you should pass DMing responsibilities to someone else.
Best Answer
Min-Maxers always have a plan. So find out everyone's plans.
Hi, I'm Thomas, and I'm a min-maxer. And I have played with a lot of min-maxers. If there is one thing that could tip you off to a min-maxer at session 0, it is that min-maxers already have a plan. When I intend to play a heavily optmimized character, I've already got my build planned out start to finish by the time I make it to session 0. And every time I have run a game with one or more min-maxers, I have been able to tell without fail at session 0 by just asking each player about their general plans for their character. When I GM, I always just ask everyone at session 0 about the long term plans for a character build, just to gauge this very thing - play style. If your GM doesn't do something similar, or your game doesn't have a GM, just do it yourself:
In my experience, the min-maxers will out themselves right there. They have already planned out how they are going to progress, and you can generally tell from the choices they intend to make if they are going to lean heavily toward optimization, assuming you have a decent idea about what optimization looks like in your game. Do note, not everyone who comes to the table with a long term plan is min-maxing. Like I said, you should be able to tell what you're getting - obvious non-optimal choice is obvious, obvious broken combo is obvious.
I think this is a solid approach if you want to be a little less on the nose than just saying "I don't really enjoy playing with min-maxers, are any of you going to min-max your characters?" But if you don't care about being subtle, you can just ask, as other answers have suggested.