Sen. Edward M. Kennedy (D-Mass.), finally an official candidate after a decade of hints and feints, leaped headlong into the presidential fray today with sharp blasts at President Carter and the major oil companies.

In a four-state campaign swing that began in Boston with a formal declaration of his candidacy, Kennedy, 47, said Carter is unprepared and unwilling to deal with energy and economic problems.

And the candidate received a public blessing from his wife, Joan, who has lived apart from him for two years. Nervous but resolute, standing before a crowd of politicians and reporters, she said she would campaign with her husband.

She did not travel with him today, however.

Kennedy's campaigning today was based on the general theme that Carter has failed as a leader. The specific case Kennedy cited time and again was the president's order decontrolling oil prices, which Kennedy said exacerbated inflation and led to outrageous profits in the oil industry.

"You can't have it both ways, Mr. President," Kennedy shouted to several hundred supporters jammed sardine-style into a restaurant in Manchester, N.H. "You can't come up here and tell the northeast governors you deplore the profits of the major oil and gas companies and then take the kind of steps you've taken."

Kennedy also took repeated potshots at Carter's suggestion that the American people are suffering from malaise.

"I say it isn't the American people that are in a malaise, it's the political leadership that's in a malaise." Kennedy complained that Carter had "relegated the problems to bureaucrats," citing presidential aides Robert S. Strauss and Alfred Kahn and former energy secretary James R. Schlesinger Jr.

"Well, I think Bob Strauss is a nice guy," Kennedy laughed. I think even Jim Schlesinger might be a nice guy. But they weren't elected president of the United States -- Jimmy Carter was."

Although Kennedy blasted the Democratic president with a relish that the most ardent Republican would admire, he is the top choice of Democrats nationwide for the presidency, according to opinion polls.

As the youngest member of the nation's best known political family, Kennedy has an enormous edge over other politicians.

But if he is a member of a famous family, he is also a man of his times. This is evident when comparing his declaration of candidacy yesterday with those of his older brothers.

John F. Kennedy's declaration in 1960 was marked by a sense of grandeur that would sound haughty, even jingoistic, today. In the presidency, he said, "are centered the hopes of the globe."

Robert F. Kennedy declared in 1968 with an outburst of passionate intensity. He said that election would determine "our right to the moral leadership of this planet."

Edward Kennedy's announcement today was focused closer to home, dealing almost entirely with current economic problems and the need for a "forceful, effective presidency" to solve them.

Kennedy laid aside his normal speaking style and delivered the address in subdued, almost stilted tones.

The formal announcement, held in an ornate, pillared Boston meeting hall where patriots planned the American revolution, had the aura of a society wedding.

The invited guests were led to their seats first, and then members of the Kennedy family -- Sargent and Eunice Shriver, with their children; Ethel Kennedy, with some of her children, and Jacqueline Kennedy Onassis -- filed in through corridors lined with photographers.

In his announcement, Kennedy offered more insight into his reasons for seeking the White House.

"The energies of our people must be marshalled toward a larger purpose, and that can only be done from the White House. Only the president can provide the sense of direction needed by the nation . . . The most important task of presidential leadership is to release the native energy of the people."

As he has done previously, Kennedy ducked efforts to make him state specifically how he would differ from Carter in handling economic problems.

But the day did provide a specific answer to one recurrent question.

When Kennedy was asked in Boston this morning what role his wife would play in the campaign, he turned to her and asked her to provide the answer. Joan Kennedy walked slowly to the lectern, and it was evident that she was extremely nervous. But her answer was direct.

"Will I campaign for my husband? I look forward to campaigning for him," she said as he stood behind her with a smile of pride and satisfaction.

"I look forward very very enthusiastically to my husband's being a candidate and the next president of the United States," she said.

Kennedy's long day ended at a rally in Chicago. By then he had lost his voice, and as he croaked out a few paragraphs of his standard speech the crowd wandered around lackadaisically. Many left while he was still speaking.