Rules module: How do I execute code just before content is deleted?
You might be looking to implement hook_delete().

You can also check node_delete_multiple() in node.module, if you want to have an idea of what Drupal core does when it delete nodes...there's other hooks that get called as well.