Depending on your hull design, you can sometime do a really good job of holding position and other times, you just have to head back out. On boats where the propeller is placed just forward of the rudder, you can really control the direction of you thrust and keep the boat head to wind. The technique is to spin the wheel hard over and engage forwards then put it back in neutral just before being pointed into the wind. This does not work on a lot of modern boats where the props are further forwards and there is a lot of windage forwards which make the boats quickly fall off the wind.
There are also a few rare boats that actually hold position really well stern to. These tend to be boats with large rigs placed very far forwards. Just using a little reverse every now and then can keep you in the same spot. You do have to be careful about moving sideways.
Realistically, it is usually easier just to go out and motor in circles slowly.