The Optimize button is used to have the game automatically choose a team of Pokémon for the player, serving as a quick team chooser. However, it doesn't take into account the stage disruptions and the Pokémon's abilities; that is up to the player to figure out. It appears when the player selects a stage, under the player's current Support Pokémon.
For the first slot, Optimize will choose any super-effective Mega Evolving Pokémon. Subsequent presses will cycle through any other Pokémon that fit the description. If no super-effective Mega Evolving Pokémon are found, it will choose any Mega Evolving Pokémon.
For the other three slots, Optimize will choose super-effective Pokémon with the highest attack power. If there are multiple Pokémon with the same high attack power, it will choose them at random.