President Reagan, coming off what one White House official called "the lost year" of his presidency, will use his last State of the Union address Monday night to try to regain the momentum of his early years in office and leave a positive historical legacy despite the Iran-contra affair, according to his aides and associates.

"He is far more energized in his final year in office than he would have been if he didn't have something to prove," said a longtime adviser.

Reagan, who will be 77 next week, is emerging from the most difficult period of his presidency and, according to many associates, is in surprisingly good spirits.

The "lost year" referred to by the White House official is not a calendar year but a period that began in November 1986 and ended last month at the Washington summit where Reagan and Soviet leader Mikhail Gorbachev signed the first U.S.-Soviet treaty to eliminate intermediate-range nuclear missiles.

During these 13 months, Reagan suffered heavy blows that altered the public perception of his presidency and for a time caused even his legendary optimism to falter.

The decline began when Republicans lost the Senate in the 1986 midterm elections after a campaign that Reagan had made a personal test of his presidency.

Before the returns were fully counted, the White House was shaken by the first revelations that the administration had traded arms to Iran in an effort to free Americans held hostage in Lebanon.

These events were followed by the firing or resignation of top national security officials and intense White House turmoil. Reagan's public approval ratings plunged, and the impact of criminal and congressional investigations into the Iran-contra affair left the White House reeling. A newly assertive Congress, taking advantage of Reagan's weakness, overrode vetoes of the clean water and highway bills.

Public confidence in the economy, at high levels after nearly five years of prosperity, was shaken by the October stock market plunge.

Reagan's long-awaited chance to reshape the Supreme Court was lost when Judge Robert H. Bork was rejected by the Senate after a bitter fight, and his second nomination, of Douglas H. Ginsburg, was withdrawn after embarrassing disclosures of his use of marijuana.

Reagan also suffered personal setbacks. The president recovered remarkably from a serious bullet wound in 1981 and from colon cancer surgery in 1985, but he recovered slowly early in 1987 from prostate surgery and for a time curtailed his travel.

Last October, First Lady Nancy Reagan underwent a mastectomy for breast cancer. Her mother died soon afterward. The president left an important staff meeting to tell his recuperating wife of her mother's death.

The year was also one in which Reagan aides and friends died, resigned or were investigated, indicted or convicted of various criminal charges. Former White House deputy chief of staff Michael K. Deaver, whom Reagan was once said to consider a son, was convicted of perjury. Lyn Nofziger, another former longtime aide, was indicted on conflict-of-interest charges for allegedly attempting to influence his former White House bosses on behalf of a client. Attorney General Edwin Meese III, an aide of Reagan's since his early days as California governor in 1967, came under investigation for his own efforts in behalf of the same client and other matters.

But a number of people who know Reagan well said in recent interviews that he does not seem profoundly affected by the calamities that have befallen friends and former subordinates.

"I've never heard him mention either Deaver or Nofziger," said a White House official who sees Reagan regularly. When reporters last week shouted questions to the president about Nofziger's trial, the president turned away without comment.

Some friends of Reagan depict him as a cheerful loner who has gone through life insulated from close friendships. "He is always friendly and polite and full of one-liners, but there is an invisible wall around him," said a California friend who has known Reagan for decades. "It's part of his appeal and his celebrity quality. He doesn't let anyone get too close."

"I have never seen the president get emotional or weep over anything related to him in a personal way, whether a family loss or a disappointment or failure of his own," wrote Deaver in his new book, "Behind the Scenes."

Another former Reagan associate said that the president, whose father was an alcoholic, "was profoundly hurt in his early youth and created fantasies from a fairly early age that he's been fortunate enough to fulfill. . . . He's spent a lot of time having to deal with some basic early hurts, so I think he can handle almost any loss."

An ex-aide traced Reagan's aloofness to his early Hollywood days when he made one B-movie after another, always with a different cast and a different director. "The cast changes, but Reagan doesn't change," said this former aide. "You could call it a weakness, but it's mostly a strength in the presidency. He's always ready for the next role and the next act."

Reagan used a Hollywood reference last week week as he exhorted political appointees to give a strong performance in their final year in office. "As they say in show biz, let's bring them to their feet with our closing act," the president said.

Friends and aides agree that he has bounced back strongly from the reverses of 1987.

"You can see his enthusiasm restored, and you can see the gleam in his eye and his health is good. . . . And for a man 76 years old, he is a marvel to behold," White House chief of staff Howard H. Baker Jr. said in an interview Friday. "I've known him for a long time, and I've never seen him in better shape than he is now."

The "last act" that Reagan will describe in his State of the Union addresss will include heavy emphasis on the necessity of prompt ratification of the Intermediate-Range Nuclear Forces (INF) Treaty and intensification of effort toward the far more difficult goal of obtaining another treaty to reduce sharply the strategic nuclear arsenals of the superpowers. Reagan will restate his commitment to regional anticommunist "freedom fighters" in Nicaragua and Afghanistan.

The president also is expected to call for ratification of the recently signed U.S.-Canadian free trade pact, which faces challeges in Congress and the Canadian Parliament. Reagan is said to consider this accord one of the most significant and underrated accomplishments of his presidency.

A "North American accord" has long been of interest to Reagan. A call for such an accord was the only new element in the speech in which he announced his presidential candidacy on Nov. 13, 1979. Baker said Friday, "I would not be surprised to see him try to extend the negotiations that he's concluded now with Canada on some basis to Mexico."

The State of the Union address has been prepared under the guidance of White House communications director Tom Griscom. The president will deliver the speech to a joint session of Congress at 9 p.m. Monday, and the four networks will televise it.