Composite a 3D object into a photograph
To bring some sort of closure to this question (as it's sure to get asked in the near future again), to get shadows and add a bit more realism, you can refer to the answer on How to make a model cast shadows onto the world texture/background?.

To answer this question with the one thing not mentioned there. You don't really need to use compositing here as you might have thought, the simplest way to do this is to model an object to mimic the shape of the object you want to use to obscure your other object(s) and while some people have and or will use some complex node setups, you can just add a new material to the 'mask object', enable Transparency, set it to Mask and turn the Alpha to 0 like this..



Here is the setup of my scene, the tree trunk has the 'mask' material applied to it and I have a ground plane to catch a little shadow to make it a bit more realistic.. I grabbed the picture of the tree from here.



and here it is rendered..



How to get it to look better is up to you and what you want..