In Oblivion this is handled by AI Packages and scripts. Each package tells the NPC what to do, when to do it and where to do it. There are several package "types," governing typical behaviors: Eat, Sleep, Travel, Use Item At, Wander, ect. The box in which each package is configured includes buttons for perameters like "Once Per Day," "Continue if PC Near," ect. Other buttons control how NPCs interact with doors: you can tell the NPC to lock or unlock a door "At Package Start," "When At Location" and "At Package End." There is a tab in which you can specify schedules: day of week, month, date, time and duration. There is a tab specifying the location at which to perform the package: a reference point within a cell, a cell in general or a specific object regardless of cell.
You can stack as many packages as you want in the AI Package List window. The game will cycle through each of them from top to bottom, rejecting packages whose parameters are not met and performing the actions specified in a package whose parameters are met.
AI Packages are automated behavior controls. If you want an NPC to do something very specific (like making Renault die in the tutorial dungeon) you write a script and attach that script to the NPC.
Also affecting NPC behavior are Aggression, Confidence, Energy Level and Responsibility. These are controlled by numbers, ranging from 0 through 100. An NPC with an Aggression of 0, for instance, will not fight even if attacked; with an Aggression of 30 the NPC will fight back if attacked; with an Aggression of 100 the NPC will always attack the player on sight.
Oblivion's Faction system also has some affect on NPC behavior. Two NPCs in affiliated factions will not fight each other (unless told to do so by a script) and may fight each other if they are in opposing factions. The Factions box is where you you list (or create) other factions and specify how those factions affect disposition.
This is just a quick overview of some of the things that make NPCs do what they do.