There are three problems: sensors, algorithms, and actuators.
The conventional sensor is an inertial guidance system. It tracks the current position and angle based on earlier position, and acceleration.
Another common sensor is a sun sensor. This can be as simple as some solar cells and shades, or as complex as a steerable telescope.
Another common sensor is a star tracker. This is usually a small (1 inch) telescope mounted at a fixed angle to a rotating bearing. A photocell or solid-state camera arrangement sees the star. There are 57 bright navigatonal stars in common use. The most commonly used are Sirius (the brightest) and Centauri (which is almost on the celestial equator.)
Algorithms calculate how to thrust (or whatever) from the sensors. The most efficient algorithm calculates a direct, single movement from the current position to the desired position. One way of calculating this is to take a standard efficient movement, and rotate and parameterize it, adjusting the actuator numbers to match.
Attitude control can be maintained by ; Thrusters : Thrusters (usually monopropellant rockets) are the conventional low-risk solution. However, they use fuel. In normal station-keeping, the fuel-efficiency of an attitude control system is determined by the smallest time it can thrust. In practice, controllers successfully adjust down to this amount, and then the spacecraft oscillates slightly, with a tiny blip of thrust in one direction, and a few tens of seconds later, an opposing blip of thrust. To conquer this fuel limitations on mission lengths and masses, sometimes auxiliary attitude control systems are used that can resolve lower angular velocities, notably momentum wheels and solar sails. ; Momentum wheels : These are electric motors that spin in the direction opposite to the direction the spacecraft needs to turn. Since they're computer controlled, and usually a small fraction of the spacecraft's mass, they give precise control. The biggest problem is that they move, and therefore their bearings can fail. To increase lifetimes, they can have magnetic bearings. ; Solar sails : Small solar sails and thermal radiation adjustment devices (adjustable reflectors) have been successfully used (e.g. on Pioneer 10) to make small attitude control and velocity adjustments. This can save large amounts of fuel on a long-duration mission by damping the oscillation rates more precisely than thrusters can achieve. ; Mass distribution : A great virtue of this system is that it requires no control system. This is how the earliest satellites were stabilized. In orbit, a long spacecraft will spontaneously orient so that its long axis points at the planet's center of mass. This is caused by a tidal force. The upper part is moving faster than orbital speed, and pulls away. The lower part is moving slower than orbital speed and pulls down. Sometimes tethers are used to connect two parts of a satellite, spread by a tide. A problem with simple tethers is that meteroroids as small as a grain of sand can cut them. ; Magnetic field coils or (on very small satellites) permanent magnets : These exert a moment against the local magnetic field. This only works where a magnetic field exists. One classic field coil is actually a conductive tether in a planetary magnetic field. ; Pure passive attitude control : For low resolution attitude control in an Earth orbit, tidal and magnetic pointing can be combined with viscous damping to get a completely passive system. Simple uncontrolled magnets and tidal pointing have a limited pointing accuracy, because the spacecraft can oscillate around energy minima. A simple solution to this oscillation is a viscous damper, a small can or tank of fluid mounted in the spacecraft, possibly with internal baffles to increase internal friction. Fast oscillation of the satellite will be turned into heat within the viscous damper. Slow oscillations have less effect.Where the satellite needs to have a preferred end (like a camera) point at the planet, usually several small electrically-fired solid fuel rockets are mounted on one end, each with thrust enough to flip the satellite end-for-end.