How does one prepare for an opponent (OTB or Online)? Do you go through recent games? How far do you normally go back? Would certain factors about an opponent dictate how you prepare for them?
There can be no one-size-fits-all as to how to prepare for an opponent, as this will depend greatly on the playing strengths of both the one preparing and the opponent, and what works for one person won't necessarily work for another. So I'm somewhat hesitant to answer at all, but I'm hoping that the following three vignettes of chess preparation will shed a little light on the matter for you, without being blatantly inaccurate or overly biased.
1. Bobby Fischer prepares for Boris Spassky. Leading up to the 1972 world championship match, Fischer famously immersed himself in a deep study of all Spassky games he could get a hold of, going as far back as he could, to the point that he basically knew all Spassky games on record inside and out. (See e.g. the mention and footage of his "big red book of Spassky" at 8:10 of this 60 Minutes report from 1972. The video's a little hazy, but you can make out that the book is Weltgeschichte des Schachs 27: Spassky.)
For someone of Fischer's prodigious talent and understanding, this kind of focused study could yield extremely useful insights in terms of both (1) concrete opening preparation for the match, and even (2) uncovering particular strengths/weaknesses in Spassky's middlegame and endgame play.
This is all well and good for grandmasters, as such particular preparation can be the best use of their time, especially as they necessarily have very strong general skills already. Most of us mere mortals, however, wouldn't be able to reap the same benefits from such an in-depth study of an opponent, for the simple reason that we don't understand enough about chess itself to truly glean much useful information from all that study, and besides, our time could be more efficiently spent improving our overall game. As to the specifics of preparation at that rarefied level of play, well, "whereof one cannot speak, thereof one must be silent."
Nevertheless, here's an account of my own very limited personal experience down at my level, which should be taken with an enormous grain of salt.
2. A relatively strong amateur prepares for a particular opponent. Even if I found the idea of preparing for an opponent to be appealing (I very much do not), I still think it would usually be a mistake for someone of my level (~ 2100 USCF) to spend much time on a finely-grained study of a particular opponent (assuming one even has access to many of the opponent's previous games in the first place), for the basic reason I spelled out above: I don't know enough to draw the right conclusions.
Despite that, I have lately found myself facing many repeat opponents because I've been playing a lot at my local club, and without having set out specifically to do so, I have ended up getting a useful sort of individualized preparation from previous games. For instance, there is a fellow expert player who I've now faced 6 times. The first two games were hard-fought draws in which I was on the defensive each time, and somewhat fortunate not to lose. The crude knowledge I obtained about him from those games, and which has proved useful, was just (1) that he is very aggressive and seemingly always looking for a direct attack, and (2) that apparently I could outplay him when things were kept quiet.
In the 4 games since, I have 3 wins and 1 loss, but that loss was only because of a fingerfehler when playing out what would've been mate-in-3 during a time scramble (probably the only time I've ever been truly angry after a game). In terms of the objective chess play, things have gone very poorly on his end since my realization about how to approach him. We have nearly identical ratings, and I believe that my recent success against him can be directly attributed to this very rudimentary sort of "preparation," namely: I know that if I play cautiously and sufficiently deaden the position against this opponent, then the resulting game suits me much more than it does him.
But that's as fine a point as someone like me can put on the matter: "I like quiet, he likes chaos." Big whoop. This is of course a far cry from the sort of preparation Fischer carried out, but that's as it should be, and even so it has proved useful for my own modest purposes. An important point here is that this information is something that I discovered naturally in the course of playing this opponent, and was not something I devoted separate time and energy to figuring out (which I maintain will often be quite a waste of time).
3. A novice prepares for a particular opponent. This really shouldn't happen, as the novice's energies should most definitely be focused on all-around improvement, rather than on any particular traits of an opponent's play. Taking what I wrote above a step further, the novice simply isn't equipped to draw many appropriate/useful conclusions at all from an opponent's earlier games, and should instead simply direct all effort toward playing good moves and a solid game.
At my level (B player) I would not bother too much preparing for an opponent. Sure, if you know your opponent only plays the Colle, you can book up some on that opening, or book up on an anti-Colle opening.
Games at my level are won or lost on tactics; little else matters.
I'd agree with point #3 in Ed's post.
For club players with 1/2 - 1 hour:
Find out what colour you are likely to have and try to find out what your prospective opponent's favourite opening(s) is/are with that colour (ask friends, lookup online). If they play several, just have a guess.
Decide if you have an opportunity to avoid this opening with something you prefer - e.g. if he likes to play the Spanish you could get in earlier with a Petroff - or if you are likely to end up in the opening of your opponent's choice.
Spend time ensuring you learn something new about your prediction for the opening, e.g.: What are the key themes/critical squares? What are the common traps, or any recent interesting departures from book?
If the predicted opening is played, you gain time and confidence at the board. If not, you've still learnt something that you should be able to remember for next time.
At one time I played in a slow time control club on ICC. I was ~1600 or so, so we weren't exactly the top level. One game, it was very clear that my opponent had looked at my recent games and found an issue in one of my opening responses. My team was pretty furious that I resigned after 10 minutes of play, but it really was a crushing hole in my opening that I've since avoided. Since then I've learned that you should clear out your history before a match, by playing random openings in bullet games or even an opening that you don't usually play, to lead them down the wrong path.