Penning a late-night Fringe play about literature's greatest double act isn't the most obvious career move for a stand-up comedian. Then again, Stewart Lee's 20-year career hasn't exactly followed the usual path. He directed and co-wrote Jerry Springer: The Opera, moonlighted as a music journalist and recently made his debut as a fiction writer in a collection of short stories based on songs by The Fall. As you might imagine, then, Johnson and Boswell: Late but Live is a suitably single-minded excursion into drama.

The two eighteenth-century literary wits, after all, went about things in very different ways. Dr Samuel Johnson confounded people's expectations of how a man of letters should behave, while James Boswell, like some historical equivalent of the music journalist Lester Bangs, preferred to print the myth.

Many years ago, Lee read Boswell's account of his trip with Johnson to Scotland. When he was approached to write the play, he decided to attempt to demonstrate how the wit of Johnson could be presented in a modern way, and to show that he could be as funny as any comedian now. He plumped for using the device of a book launch, in which Johnson (the comedian Simon Munnery) and Boswell (fellow funnyman Miles Jupp) attempt to ply their wares to a thoroughly modern audience - a set-up that allows them to talk about Scotland in the 21st century rather than the eighteenth.

"What became more interesting and relevant to now," Lee explains prior to a warm-up stand-up show at Glasgow's Stand comedy club, "is how Boswell clearly had an agenda on how he wanted to present Johnson. It was a father-son hero-worship thing. And it's also about how PR works, and how events are recorded, and what was the difference between what Johnson might have been like and how Boswell chose to record it.

"Boswell made a career out of following Johnson around and writing down all the funny things he said. So apart from three or four incidents from the story, I started ignoring most of the historical side of it, and thinking about what it would be like to have these two men onstage, one of whom clearly hero-worships the other.

"We ended up looking at how Jonathan Ross interviews people he's clearly a bit in awe of from his childhood. Boswell actually says at one point, I'm a big fan of your work. We all are.'"

Lee began thinking of some of his own heroes, fully-paid-up members of the awkward squad such as the late Peter Cook, former Sex Pistol John Lydon, Morrissey and (of course) Mark E Smith, frontman of Lee's most beloved band, The Fall. All have determinedly confounded any attempts to co-opt them into showbusiness's cosy, PR-led inner circle, making for stubbornly inconsistent, often self-destructive but altogether more interesting careers.

"All these people have a sense of what their public persona is," Lee points out, "and are expected to be caustic and witty. But as they get older, you can see them get rather tired of it. In interviews, Smith either blocks everything or else decides to be hilarious. Morrissey's like that as well, and some of Peter Cook's interviews towards the end of his life were the best things he ever did.

"There's a brilliant quote from Johnson that says something like Men in advanced years should not repeat the simplest elements of their art'. Obviously the thing that follows Johnson round all his life - his equivalent of Ricky Gervais's funny dance - is When a man is tired of London, he is tired of life'. Boswell tries to get him to say it all the way through, because that's his catchphrase. So when someone like Johnson becomes known for a particular thing, you can either choose to roll with it or run from it. It's like whenever Ricky is asked to do his dance, he seems to be genuinely irritated - but will trot it out at a big enough benefit event. It's the same for Johnson, where it's all become a bit of a chore for him."

THE show isn't a history play at all, then, but is more about the fawning sycophancy of today's celebrity culture. It's a world Lee has brushed up against - once when he was represented by the uber-glossy comedy agency Avalon, and then again after the runaway success of Jerry Springer: The Opera. For all his pride in a work that became one of the biggest and most controversial success stories of recent times, there were elements of it he clearly found uncomfortable.

"I would never want to work in commercial theatre again," he says. "With Springer, once we'd done it once, trying to explain to commercial producers that you couldn't just put the next cast in, because it would change things because they'd have a different sets of personalities, was extremely hard work."

Lee prefers to exist on his own terms. After almost giving up stand-up seven years ago, he took on Springer at a time when his profile was so low he could get away with anything.

Last year he directed the comedian Phil Nichol in Eric Bogosian's play Talk Radio, and he has just co-written a play performed in a flat (notably by Johnny Vegas at the Manchester International Festival). Next, he has a few vague thoughts about scripting "a small folk musical about the Napoleonic wars".

"I'm lucky in a way, because I do seem to be allowed to get away with doing different things," he says. "It wasn't a deliberate strategy, but nobody seems to think it's that weird me doing a play about Johnson and Boswell."

Taking inspiration from his musical heroes, Lee's DIY approach now extends to selling self-produced CDs and DVDs through his website without being beholden to big record labels or expensive PR companies. "You look at The Fall or some of the free jazz people like Derek Bailey, and they put out the stuff themselves. That's the way I've started doing it, and it is possible to survive doing that. It's not as arcane or mysterious as promoters and managers make out. Part of it is to not get involved with people whose overheads are so high that you have to do things in a certain way to break even.

"Once Springer moved into a commercial space, the overheads were so high it was impossible to get a royalty. It was very satisfying creatively to be able to play with that level of resources, but on a personal level it was a financial black hole, and in a way the show being destroyed by the American Christian right was a good thing.

"The problem with big things is that investors do start talking about a piece as if they owned it. My attitude is: we wrote it and we've invited you in on it, so don't start dictating terms. I remember an investor saying to me, You can't just do what you want.' After 20 years, I think I can."

  • Johnson and Boswell - Late but Live is at the Traverse until August 26. Stewart Lee - 41st Best Stand-Up Ever is at the Udderbelly until August 27.
  • www.stewartlee.co.uk