Cal40John's two links cover it all but for perspective - it all goes together.
main trim can be considered a compromise between fast, steering
angle, drag and acceleration. The shape is optimized (compromised?) for -
+ flat sea
+ lumpy sea
At about 12-15 knots all boats are "fully powered" then it is a matter of practicing to achieve best pointing and boat speed at the same time. I know there are electronic sailors but you can learn this easily with boat speed and a good windex.
The first goal is always boat speed. The helmsman's "only" goal is boatspeed. He should know what boatspeed to expect in given conditions and sail the boat to boat speed. If the boat is not pointing there is a trim issue that needs to be worked out.
The helmsman and trimmers are in constant communication, weatherhelm, steering
angle, acceleration all need to be discussed constantly.
There are other ways to manage a boat but I teach the helmsman to pursue speed, the tactician to pursue course, and the lead trimmer (usually the mainsail
trimmer) to be in charge of sail trim and pointing. These three effectively manage the boat.
I have been on many boats where the roles re not defined and there is anarchy. Lots' of shouting and conflicting instructions. Nothing worse for a trimmer to have 3 people telling him/her how to trim.