Do I control my Companion and his/her actions or does the DM?
If I control them, does my PC have to be there to give the order? For example, could my PC's wolf stand guard while the party sleeps with me controlling him as a player?
Technically, the animal companion is a non-player character. You do not control it. Instead, it is a creature of its own desires, experience, and so on, and can and will act independently of the player. Within D&D, independent creatures that are not player-controlled are controlled by the DM. This is akin to how cohorts work (e.g. the Leadership feat).
You can use Handle Animal to direct your animal companion. As a special bonus, handling your own animal companion is a free action; usually it takes more effort than that. This is a very good thing in combat.
But Handle Animal only goes so far; it allows you to train the animal companion in certain actions, and order them to use them, but it is still up to the animal to actually follow through. Luckily, animal companions are quite exceptional, and also have a deep bond of loyalty to their druid. You can reasonably expect an animal to obey well and honestly attempt to act in your best interests.
Almost everyone just allows the druid’s player to also control the animal companion. It’s just easier. The Handle Animal checks you need are easy and druids get a big bonus for handling their animal companion, and the animal companion’s inherent loyalty mean that it should be following those orders very well. The end result is that the animal companion almost always does exactly what the druid wants anyway – it’s easier to cut out the middle-man.
Unless you abuse your animal companion or something. As a DM, that sort of situation might prompt me to take control of the animal companion back.
Animal Companions are independent creatures, they act on their own. You can direct them using Handle Animal. Druids get special bonuses when handling their Animal Companion, making it both easier and faster. A Druid with +10 total Handle Animal can use the Handle option as a free action, with no roll required. (Commands listed under Push are more difficult.)
Animals can be told to do things that your DM decides an animal can realistically do. Several examples are listed on Handle Animal as tricks. An animal trained in a trick can be commanded to do it. How long it'll keep doing it is up to your DM, but I'd consider it reasonable to suggest that an animal specifically trained to guard would obey a Guard command even if the PC isn't there after giving that command. Of course, the animal won't stay until it starves to death. (Animal Companions get bonus tricks, letting them know more of them.)
Under the normal rules, you don't control the animal. You control your PC, and use Handle Animal to direct the animal, but the DM controls the animal. Some DMs let the PC control the animal except in unusual cases, so maybe you can in your game. That's a question for your DM. If you are allowed to, please keep in mind that it's an animal and not a human, and to play it appropriately. :)
So in your example, you'd tell the animal to guard. You go to sleep. If something happens, the animal reacts according to the DM's interpretation of what the animal would do (as you are not awake to give new commands). If your DM lets you control the animal, then you could play it instead.
Note that although the animal should have its own initiative, this is often not done in practice. It tends to be awkward to play that way, that question and its answers expand on that.