A year ago, Sylvester Stallone had $106 in the bank. His wife was pregnant, his bull mastiff was starving and he couldn't pay the rent on his seedy Hollywood apartment. What to do?

Well, one answer was that Stallone, a sometime actor-turned-screenwriter, could sit down and in 3 1/2 days write a screenplay with a meaty starring role in it for himself, persuade someone to film it, and wind up a millionaire. Improbable? Pessimists might say so, and advise Stallone to try something more sure, like the Irish Sweepstakes. Impossible? Well, no, because you see, there's this new movie, called ''Rocky.''

That's Stallone up there as ''Rocky,'' Rocky Balboa, a tender-hearted, down-and-out Philadelphia club fighter known as ''The Italian Stallion,'' who almost becomes heavyweight champion of the world. And the words Stallone is mouthing on screen are the words he wrote in 3 1/2 days and sold to producers Irwin Winkler and Robert Chartoff on the condition that he would play ''Rocky,'' and not Burt Reynolds, or James Caan, or Ryan O'Neal, who were being mentioned for the part.

The film was shot in 28 days (''The gestation time for a water bug,'' Stallone says wryly), on a shoestring $1 million budget, and now, with critics split down the middle with some raving and other deploring, and United Artists predicting ''Rocky'' will gross more than $40 million, Stallone is finally smiling. You see, he has 10 percent of ''Rocky.''

That's enough to make anyone jubilant, and he is. In an interview the other day in the Sherry-Netherland Hotel, the 30-year-old actor, known as ''Sly'' to his friends, laughed repeatedly, rolled off a steady stream of one-liners, snapped his fingers to recorded rock music, answered his constantly ringing telephone with the greeting, ''City Morgue,'' and said, gleefully, several times in his basso profundo voice, ''I am one of the great bull artists of all time!'' There is none of the brooding intensity of Al Pacino or Marlon Brando, with whom he is being compared. What Sylvester Stallone radiates is boyish mischief.

One of the few ways to make him get serious is to ask how his own life compares with Rocky's. ''There are certain parallels,'' he replied, chewing on a yellow pencil. ''Rocky had drive, and intelligence, and the talent to be a fighter, but nobody noticed him. Then when opportunity knocked, everybody said, 'Hey, there's Rocky, he's good.' That's what happened to me. The fact that we both went the distance when we were finally given the opportunity, that's the main parallel.''

''It's funny,'' he goes on, his big brown bassethound eyes growing sad, ''there's a great herd of people who were holding back compliments for years that are now coming forth and saying, 'I like you.' It happened to Rocky, too. I feel like saying to them, 'Where were you when I was living in Hotel Barf, eating hot and cold running disease?' They say, 'Oh, we were holding it back, Sly, because we didn't want you to get a swelled head.'''

All of a sudden, Stallone remembered he had forgotten to take his vitamin pills. He swallowed 44 of them, his nightly ration of the 113 he says he takes every day. As Stallone sees it, his body is a temple. He lifts weights regularly, which accounts for his muscular pumped-up upper body that is out of proportion with the rest of his body. He obviously likes people to notice his efforts: The snug black T-shirt he was wearing emphasized his 46-inch chest and his bulging, 16-inch biceps.

''You know,'' he said, returning to the subject of ''Rocky,'' ''if nothing else comes out of that film in the way of awards and accolades, it will still show that an unknown quantity, a totally unmarketable person, can produce a diamond in the rough, a gem. And there are a lot more people like me out there, too, people whose chosen profession denies them opportunity. When that happens, their creative energies begin to swirl around inside, and erode them, and they become envious, vindictive persons who turn to drink. I, myself, turned to fighting; I averaged a fight in New York City once every four or five weeks. Now when I reflect back on it, I know it was just a release for creative energy.''

Stallone, whose only leading role before ''Rocky'' was in a 1974 low budget flop called ''The Lords of Flatbush'' (he was also in ''Capone'' and ''Death Race 2000''), turned to screenwriting out of frustration at not being able to get good acting jobs. He was also influenced by his mother, who dabbled in astrology and predicted he'd make his first big success as a writer. Stallone sold a few scripts, mainly to television, before conceiving the idea of ''Rocky,'' which was inspired by an actual championship fight in 1975 between Chuck Wepner, know as ''The Bayonne Bleeder,'' and Muhammad Ali, the world champion.

''I was watching the fight in a movie theater,'' he said, ''and I said to myself, 'Let's talk about stifled ambition and broken dreams and people who sit on the curb looking at their dreams go down the drain.' I thought about it for a month. That's what I call my inspiration stage. Then I let it incubate for 10 months, the incubation stage. Then came the verification stage, when I wrote it in 3 1/2 days. I'd get up at 6 A.M. and write it by hand, with a Bic pen on lined notebook sheets of paper. Then my wife, Sasha, would type it. She kept saying, 'You've gotta do it, you've gotta do it. Push it, Sly, go for broke.'''

Actually, there were two more drafts of ''Rocky'' after the first one, during which Stallone hung ''muscle and skin'' on his characters. ''In the first draft, I always try for a skeletal structure,'' he said. ''Then I begin to inject humor and idiosyncrasies. You know, I just don't believe these guys who say it takes them 19 years to write something. I just force myself to put it down and get it done.''

From the beginning, Stallone intended to play ''Rocky.'' Although there was much interest in Hollywood for his script, the money men all wanted a name actor in the part. The bidding went up to $265,000, but Stallone refused to sell, unless he could play the lead.

''I never would have sold it,'' he says now. ''I told my wife that I'd rather bury it in the back yard and let the caterpillars play 'Rocky.' I would have hated myself for selling out, the way we hate most people for selling out. My wife agreed, and said she'd be willing to move to a trailer in the middle of a swamp if need be.''

Finally, Stallone got his way. He even wangled parts for members of his family. His father, Frank, a retired beautician and real estate dealer, plays the timekeeper in the fight scene; his 26-year-old brother, Frank, Jr., who recently signed a recording contract with RCA, plays a street corner singer; and his bull mastiff, Butkus, plays the dog. ''They work cheap,'' Stallone said, laughing. ''But I'm worried about Butkus - he'll always have problems with dialogue.''

The actor said that while he hadn't yet been able to fathom Butkus's creative process, he knew definitely that his own was not ''The Method.'' ''I think I'm an instinctual actor,'' he said. ''I don't understand terms like 'tuning your instrument.' I'm not an oboe or a bass fiddle. I'm a very rehearsed actor. I learn my lines ahead of time so that I know mine and everyone else's far in advance. That way I can give the illusion that I am ad libbing and be comfortable on the set. So many actors these days learn their lines at the last minute, or use cue cards. I just couldn't do that; I'd be too uncomfortable.''

The 5-foot-10-inch, 175-pound actor, who had never had any formal boxing instruction, went into training six hours a day for five months before ''Rocky'' began filming. He got up at dawn to run five miles on the beach, shadow-boxed around the apartment, and worked out at a gym, where he punched the punching bag, did pushups, and had a medicine ball thrown into his stomach. He was preparing for the film's climax, the championship fight, which he and director John Avildsen choreographed punch-for-punch. ''There were 14 pages of left, right, right, left, left hook,'' he said. ''What looked like haphazard throwing of punches was an exact ballet.''

Because of the rugged, he-man quality of his character in ''Rocky,'' Stallone has been hailed as the first leading man in a long time who projects the image of a Real Man. Is he as macho off the screen as he is on? ''If macho means I like to look good and feel strong and shoot guns in the woods, yes, I'm macho,'' he replied, smiling. ''I don't think that even women's lib wants all men to become limp-wristed librarians. I don't know what is happening to men these days. There's a trend toward a sleek, subdued sophistication and a lack of participation in sports. In discos, men and women look almost alike, and if you were a little bleary-eyed, you'd get them mixed up. I think it's wrong, and I think women are unhappy about it. There doesn't seem to be enough real men to go around.''

Does that mean he is a great admirer of those two other movie tough guys, Marlon Brando and Al Pacino? He hesitates. Finally, ''They seem very intense. I definitely admire them, but the actor I love is Peter O'Toole. He is so free. I know this man was probably just out there chasing the script girl, and then when the cameras start rolling, he turns on such power. I am in such awe of him.''

Swabbing his lips with chapstick, Stallone said he had a trilogy in mind for ''Rocky/'' In Part II, Rocky would go to night school and enter politics and eventually become Mayor of Philadelphia. And in Part III, he would be framed by the political machine because he was too honest, impeached and wind up back in the ring at 37, broken down but happy.

In fact, a happy, upbeat ending, a striking feature of ''Rocky,'' will probably be incorporated into all of Stallone's future scripts. ''I've really had it with anti-this and anti-that,'' he said. ''That silver cloud always has to loom I want to be remembered as a man of raging optimism, who believes in the American dream. Right now, it's as if a big cavernous black hole has been burned into the entertainment section of the brain. It's filled with demons and paranoia and fear. Where are all the heroes? Even the cowboys today are perverts - they all sleep with horses. Let other people suffer and do all those pain things and put their demons up on the screen. I'm not going to.''

More chapstick, more thought. And then: ''People require symbols of humanity and heroism. Yet today, a man brings his family into a theater, and there he sees a man pull out his knife and cut a kid's head off, and a woman is being run over by a Ford Mustang and the man in the theater says, 'Is there anybody here I can identify with? Is there anything here I want to see?' And the answers are no, no. But he sees 'Rocky' as a simple man, a man he can identify with, a man who doesn't curse and who likes America, a man who's a real man. That's what people want to see these days.''

Using his own upbeat, anyone-can-make-it-to-the-top formula, Stallone's own life story might serve as material for a movie. He's thinking about calling it ''From Roaches to Riches.'' The elements: Born to a bickering Italian couple in Hell's Kitchen . . . farmed out to foster homes while parents worked . . . grew up in Monkey Hollow, Md., where his mother ran a health spa . . . was a juvenile delinquent who attended 12 schools by the time he was 15, and was kicked out of most of them.

After high school in Philadelphia, where he had been a star fullback and discus thrower, Stallone enrolled at the American College in Leysin, Switzerland. Finding that money was scarce, he teamed up with classmate Prince Paul of Ethiopia to open a hamburger stand for the student, who had never tasted them before. Another part-time job required him to shoo men away from the girls' dormitory. He soon found, however, that it was more profitable to look the other way, 2 francs an hour, to be exact. ''I earned my plane fare home that way,'' he said, smiling.

He flew to the University of Miami, where he studied drama for two years, then moved to New York to become an actor. Instead, he found work cleaning lions' cages at the Central Park Zoo, and ushering at the Baronet Theater, where he was fired for trying to scalp a ticket to ''M.A.S.H.'' for $20. The sucker turned out to be Walter Reade, who owned the theater.

Now that the money is about to roll in, what does Stallone plan to do with it? ''I want to bank a lot of it for my kid [Sage, a 6-month-old-boy],'' he said. ''And I want to build myself a pyramid, which is the purest, most powerful structure ever devised. And I'd like to buy land in California, and maybe start some workshops for actors, and eventually get into a position where I could use actors who are not established stars.''

And no doubt he will use some of that money to move Sasha and Sage out of the 1 1/2 bedroom apartment with the punching bag in the living room and the roaches in the kitchen that they now rent for $215 a month ''in the pancreas of Hollywood.'' Stallone plans to remain on the West Coast, though, ''because I died in New York, and I was reborn in Hollywood, and I owe my allegiance to that town.''

Stallone has not yet decided on his next movie, but is eager to play the starring role in ''Superman,'' a $25 million production with Marlon Brando and Gene Hackman. Stallone is also interested in doing a film about Edgar Allen Poe, in which the author would be portrayed ''not as a dour dipsomaniac, but as a rogue, a real rake.'' And if both of these fall through, he may do a film he has written himself, called ''Sinsilver,'' about a Hassidic Jew in the Old West, and based on ''a reinterpretation of the Communist Manifesto.''

Sinsilver, no doubt, will triumph over great odds and the film will have a happy ending. Doesn't this kind of naive movie give false hopes to unfortunate people?

''What do you mean?'' Stallone bellowed. ''A peanut farmer has just become President of the United States. That's the greatest inspiration story of all time. He didn't come from wealth, he made his wealth. He went to his mother with dirt on his overalls and said, 'I'm going to be President.' He's understated, a common man, and that's why he won. I always say, 'If you lead with your heart, lead with your heart, and it will carry you much further than your brains will.'''