Defensive play can be found in all phases of the game (opening, middle and even the endgame). In the opening, it's a good idea to study a variety of openings for black such as the King's Indian Defense and The French Defense. However, too much in the way of defensive play in the opening allows your opponent to outright control the center of the board early on. This can be a disaster against a stronger opponent.
In the middle game, it's a good idea to concentrate your efforts on defensive play if your playing an aggressive attacking opponent. This is an important point since you'll get better when playing stronger players. One thing I recommend to my students, when playing stronger aggressive players is to not try and outplay them. Build up a good defense and force them to bring the fight to you. This doesn't mean that you should play passively. You want to play defensively but always keep an eye out for attacking opportunities.
Here are a few books that might help you as well as some videos and Chessbase Trainers:
Books: Winning Chess Middlegames (Sokolov) (covers attack/defense)
The Middlegame in Chess (Borovsky) (covers attack/defense)
How to Defend in Chess (Crouch)
Starting Out: Defensive Play (Dunnington)
Videos: Foxy Video 87: Attack, Defense, Space & Time Easily Explained (Andrew Martin)
Chessbase Trainers: First Steps in Defensive Play (Andrew Martin)
The Andrew Martin video and Chessbase Trainer are great because Andrew has a very practical and clear way of explaining concepts and positions. You might also consider looking at books written for children. I have my adult students refer to children's chess books all the time because the explanations are clear and to the point. However, some adults are not fond of being seen with "kids" books so I'll refrain from title suggests for now.
One of the things that happens when we study chess is that we're told that aggressive play is the way to go for improvers (players who know the basics and are moving on to start club level playing). Because of this, we ted to concentrate our studies on attacking chess rather than defense chess. While it's a good idea to play aggressively when possible, we all eventually find ourselves in a position that requires careful defensive measures. It is at the moment that we often become lost.
If you look at high end master level chess, you'll notice that in most games, both players carefully coordinate their pieces to maximize the pieces activity which is somewhat defensive in nature. Master players know they cannot launch all out aggressive attacks on their opponent early on in the game (note, there are always exceptions to this idea). Instead, they build up the position during the opening and start of the middle-game. They exercise sound defensive ideas. Try an Andrew Martin DVD/Video. He has done a large volume of them, especially regarding specific openings and presents both offensive and defensive measures in each video. The good news is that you've realized the need for a good study of defensive play.
As for the endgame, defensive play can save an otherwise losing position (often turning a potential loss into a draw).
whats the best way to learn defensive play?