'Animal masks" reads the cardboard box in the corner of the rehearsal room.

A mandolin lies abandoned by the kettle. Off to one side a dancer is running through her moves, tying imaginary ribbons round an unseen maypole. Meanwhile, torrential rain is battering against the room's perspex skylights, so violently it almost drowns out the haunting Gaelic harmonies of the seven singers sat in a semi-circle. They switch to something more robust, a 13th-century hymn in Middle English. It's entitled, jarringly in the circumstances, Summer Is A-Coming In. The rain continues to batter. It's all as good an introduction as any to the strange, skewed world of The Wicker Man, one of agricultural necromancy and free-range deviants.

Now celebrating its 40th anniversary, The Wicker Man has become that rarest and most circular of things: a film about cultism that in itself became a cult. Within the past decade particularly, The Wicker Man has ascended into a select band of cinematic immortals, as the so-called Citizen Kane of horror movies. Shot around Dumfries and Galloway, and studded with weird, yielding ditties in praise of bosky naughtiness, it has been restored and remastered, referenced and reverenced. There are shelves of academic Wicker Man analysis and, at the last count, four Wicker Man television documentaries. It has even survived the most calamitous of Hollywood remakes starring a bewildered Nicolas Cage. The Wicker Tree, a sequel of sorts by the director of the original, is imminent. An Appointment With The Wicker Man, a theatrical interpretation of the film, written by Greg Hemphill and Donald McLeary for the National Theatre Of Scotland (NTS), goes on tour later this month.

The Wicker Man is now part of the language. Just as we know a Walter Mitty character is a fantasist or that a Mrs Robinson is a predatory older woman, we know what's meant on hearing that something is a bit Wicker Man. It's a phrase that evokes every urban prejudice against life in remote rural communities; the lurking sense that something sinister is going on in every woodshed; that humanity gets up to no good when its nearest neighbour is three miles distant.

Those villages where you can still buy golliwogs, mousetraps and tea-towels with clowns on – they're a bit Wicker Man; Orkney pubs where you won't get served – they're Wickerish too. As Sherlock Holmes tells Watson in The Adventure Of The Copper Beeches: "Look at these lonely houses, each in its own fields. Think of the deeds of hellish cruelty, the hidden wickedness which may go on, year in, year out, in such places, and none the wiser."

Given the prevalence in Scotland of such isolation it's scarcely surprising that the film – and the NTS production and The Wicker Tree – mine some faultline in the national psyche. The Wicker Man is the anxiety dream of the city-dweller put on to celluloid.

One image recurs in the film and has entered our visual lexicon of the unspeakably creepy: Summerisle's villagers rising with sudden vigilance from behind low walls, their faces obscured by animal masks like those piled up in the rehearsal room box.

"We've watched the film a couple of times together as a company," says Hemphill, "and sometimes there's a bit of tittering going on. The very camp pub landlord always gets a laugh, or some of the lines haven't aged well. I sit there thinking: 'How dare they laugh – this is a classic, can't they see?' But then I realised the more they laugh the more powerful the ending becomes, when the horror of Howie's situation kicks in. And they were silent for the last 20 minutes – you couldn't hear a pin drop. Because The Wicker Man is not a traditional horror movie. It doesn't set out to scare you; it sets out to trick you."

Conceived by playwright and screenwriter Anthony Shaffer, The Wicker Man's story is as well known now as that of Whisky Galore! The devout Sergeant Neil Howie (Edward Woodward) regulates the sleepy Highland port of Ullwater with unsmiling probity. He receives a letter from Summerisle, a seldom-visited private fiefdom, alleging that teenager Rowan Morrison is missing. Howie leaves by seaplane immediately.

What he finds is Sodom twinned with the Arran Folk Festival. The mysterious Lord Summerisle (Christopher Lee, forsaking his cape for a tweed jacket) has allowed the islanders to abandon Christianity and revert to the Old Religion. Superstition and folklore hold sway, as does a cult of fertility; teenage boys are deflowered ceremonially by Willow MacGregor (Britt Ekland). Maypoles and phallic topiary dot the landscape. Churches lie in ruin. Couples fornicate openly after carousing in pubs free from licensing restrictions. Through Howie's eyes we see a wild, unfettered pagan community that disgusts him.

It's all a ruse, of course. Rowan Morrison is not missing. The island's apple crop failed calamitously last year and the Old Religion demands that the goddess be appeased. What ensues is perhaps one of the most unforgettable climaxes in all cinema. The "Christian copper" is dragged to a 30ft-high wicker effigy and placed high inside it while torchbearers set it aflame. As the community of Summerisle dance and sing below, Howie goes to meet his maker, his blood-curdling screams for mercy borne away on the wind.

Yet it isn't simply the movie's plot for which posterity treasures The Wicker Man. The making of the film is one of the most infamous black comedies in cinema history. Everything that could go wrong did – twice. The film was something of a whim, a one-off, from the outset, cooked up to aid Christopher Lee escape his typecasting as the tall, dark and gruesome focus of the Hammer horror canon. "Christopher had come to me," Anthony Shaffer told me in 1999, "and said, 'I'm very unhappy. I want to do a film without women who look like Barbara Windsor running up and down papier-mache corridors screaming, without the contact lenses and the fangs.' He wanted to do something more manly, with more originality."

Despite this caveat, the film was rushed into production with a cast described best as motley. Bit players were hired from the Citizens Theatre in Glasgow. Local Gallovidians got their chance. There was also a practising Australian white witch and former wife of Sean Connery (Diane Cilento); a fixture of the Scottish pantomime scene (Walter Carr); the man who taught David Bowie mime (Lindsay Kemp, playing the aforementioned camp landlord); a Pole (Ingrid Pitt) portraying, in her words, a "nymphomaniac librarian"; and a Swede, Britt Ekland, whose accent was so thick it required redubbing by Annie Ross.

The panicked production schedule meant a story set at the height of spring needed to be shot in late October, on the blustery cliff tops of coastal Scotland. The rush meant Shepperton studios had not been booked for interiors. Plastic apple blossom was hung on wind-blasted trees. Temperatures on set dropped so low the cast sucked on ice cubes to prevent their breath condensing on camera. They changed their costumes in the public toilets of a nearby caravan park. Tempers flared constantly. After work, in the bar of the Ellangowan Hotel in Creetown, the hard-drinking cast sought to deepen their acquaintance with Glenmorangie, or the Big GM as it was known. Ekland caused a press storm when she claimed in an interview that Newton Stewart was "the most dismal place in creation".

Yet worse was coming. At a time when Hammer horror was being supplanted by the suburban sex comedy, the board of producers British Lion decided no audience existed for a horror-musical set in the Highlands. The sole release the film could expect was as a supporting feature to the Julie Christie shocker Don't Look Now. Becoming such, though, meant much footage had to hit the cutting-room floor. The abbreviated orphan film was pushed out on a despondent tour of Britain's provinces in December, 1973. "I mean, this was an Anthony Shaffer picture," Edward Woodward told me. "In contemporary terms that would be like a Steven Spielberg film going straight to DVD – it was virtually unthinkable." By 1974 The Wicker Man was all-but forgotten, if it had ever been noticed.

Then something curious began to happen. In 1976, the film was reissued by a new distribution company in the US and began to break box-office records in San Francisco and New York, aided by a review claiming it was a "philosophical soft-core Scottish thriller musical". Its discarded footage was incorporated into a new version released on home video. In Britain, the Wicker Man Appreciation Society, a sodality of furiously photocopying devotees, made an appearance. Gradually, it became become a fixture in British television's repertory of late-night horror cheapies.

Hemphill saw the film first, in 1986, in a London hotel, as his family were relocating from Montreal to Glasgow. "I was 16 and I knew nothing about it, which is the way you should come to a film with a climax like that," he says. "I assumed it was just a weird and wonderful midnight horror film. So, when the ending came I thought, 'Oh well, he's The Equaliser – he'll get out of this. He'll climb out the back of the wicker man. Or it'll rain.'

"And it didn't. I sat there thinking, 'What the hell is this? What? No!' I remember being quite upset and disturbed. Because the islanders didn't think they were giving Howie a horrible death. They were smiling as he burned, they were killing him with kindness. That's the really creepy thing that ends up haunting you."

Vicky Featherstone, artistic director of the NTS and director of the play, saw the film in the same period while studying film and theatre at Manchester University. "It appealed to the anarchic drama students in us," she reflects. "At the time there was a lot of interest in shamanism and expressive dance, I suppose, and The Wicker Man seemed to fit in with all that." Featherstone went on to co-create the cuddly-country ITV drama Where The Heart Is and head the Paines Plough company. Since 2007 her tenure as artistic director of the NTS has been widely considered a huge success, vindicating the board's decision to appoint from outwith the narrow confines of the McTheatre community. Unafraid to think big or cross-fertilise with other forms, the 44-year-old from Surrey has overseen a growing slate of surefooted productions, including Black Watch, The Missing – from the novel by Andrew O'Hagan – and Alan Cumming in The Bacchus.

"I was having a conversation with my husband [television screenwriter Danny Brown] about whether there was a gap in the way the NTS made theatre, particularly in terms of addressing audiences who were culturally hungry but who didn't necessarily consider themselves theatre-goers," she says. "That took us on to the comedian Simon Pegg, whose work is full of film references, and that took us on to The Wicker Man."

Featherstone brought the notion to Hemphill, co-creator of the BBC comedy fixtures Chewin' The Fat and Still Game, and collaborator Donald McLeary, a writer and performer whose intimacy with rural skulduggery and police procedure were honed during his stint as PC Plum on the children's TV show Balamory. The connection was only strengthened when he noticed a coffin in one scene of the film had "McLeary" written along its interior. The pair convene Sunday evening social gatherings at which two horror films are watched, nights at which The Wicker Man is staple viewing. "We were such fans of the film that even if Vicky had asked for us for a line-by-line recreation we would have written that," says Hemphill, "but it would have been rubbish. A stage show, we thought, would need to have the same mesmerising soft-porn sexual madness of the film. That was our jumping-off point – we can't do a theatrical version of the film: so what do we do?"

An Appointment With The Wicker Man is the answer, a Scottish comedy hybrid of Hamlet and Abigail's Party, in which rural claustrophobia weaves like bindweed through the delusions of an amateur theatre troupe. In the village of Loch Parry, a ramshackle crew of egotists and ingenues have gathered to mount the stage version of the film. They profess to be obsessed with it, though they do seem rather sketchy on the details. "I've seen it," says Callum, the show's director. "Well, I've seen most of it bar the last 10 minutes. Lenny Henry was on the other side."

The faltering production is dealt a further blow – or is it? – when its Howie, played by one Roger Morgan, disappears in circumstances the remaining cast members seem reluctant to discuss. He's replaced by Rory Mulligan, star of the Taggartesque TV drama Blood Beat, another actor, the observant will note, who shares initials with Rowan Morrison, the teenage bait of the movie version. Mulligan starts his assignment believing the Loch Parry Players to be enthusiastic incompetents. Gradually, though, as the hopeless production is rehearsed, a weirder picture emerges of the Loch Parry Players. In the wilderness, lives can twist into strange gnarled shapes and drastic measures are often the only remedy. "It's important to point out we're not making fun of the film itself," says McLeary. "The jokes lie in how the film's situations reoccur in the lives of this indifferent theatre company. The Wicker Man is so deeply embedded in the culture now you can play with what audiences know about it. You say graveyard scene and people know what that involves."

In all, An Appointment With The Wicker Man is a hugely affectionate anagram of the film, playing upon one of its most crucial themes, the unbridgeable gulf between the urban and the rural. In its clever, broadly comic way it reminds us there is a range of reasons why this cheap, jinxed B-feature has come to enjoy such a singular afterlife. There's the wry, icy wit of Anthony Shaffer's unmatchable screenplay, of course, quoted throughout, and the spectacular brutality of the film's climax. It would be unfair to disclose how this finale is handled on stage but perhaps give thanks to the appropriate deity that Featherstone's initial idea wasn't pursued; toward the play's end a fire alarm was to sound, the audience escorted out – then not escorted back in again. "The idea was to leave the audience unsatisfied and uneasy, as the film does," she says. "Then the problems with the idea occurred to us."

Over and above its ending are the film's thematic concerns. The film seems to possess a quality that borders on clairvoyance. When The Wicker Man was made, faith and religiosity were hardly crucial issues of the day, in Britain at least. Forty years on, though, and we live each day with the threat of the extremes to which some will go to externalise their beliefs. The barrier between civility and barbarism is increasingly permeable. The Wicker Man argues that all faith – whether the dogmatic Christianity of Howie or the free-range deviancy of Summerisle and his neo-pagans – is man-made and socially constructed. Its message is one of a deep and abiding liberal humanism.

And just as The Wicker Man is a film about cultism that became a cult it is also a phenomenon about the life force that refuses to die. Howie believes God is the universal animating force; Summerisle believes it is nature. Whatever it is, on whichever side of the date you fall, The Wicker Man and its reputation can't stop flourishing, as An Appointment With The Wicker Man is just the latest entity to demonstrate.

"The film survives because it invites you to think for yourself; it insists in it," Anthony Shaffer told me in 1999. "There is something in the very frames of that picture which is saying, 'I am living and I will go on living.' I think Sgt Howie and Lord Summerisle would have approved of that -" n

An Appointment With The Wicker Man opens at the Macrobert Arts Centre, Stirling on February 17-18 then travels to Aberdeen, Glasgow, Inverness and Dunfermline. Visit www.nationaltheatrescotland.com. Allan Brown is the author of Inside The Wicker Man: How Not To Make A Cult Classic, published by Polygon, priced £12.99.