President Carter was savagely and simultaneously denounced on energy from opposite directions yesterday, first by the oil industry and then by his presidential challenger, Sen. Edward M. Kennedy (D-Mass.).

At the annual meeting of the American Petroleum Institute in New York, that organization's chairman, John E. Swearingen of Standard Oil of Indiana, accused Carter of demagoguing against the industry.

"For a president who ran on a platform of never lying to the people, he certainly seems to be stretching truth to the snapping point," said Swearingen. The chairman of Amoco added of Carter, "the problems of his office strain his ability to deal with them."

As the oil man was denouncing Carter, especially for the House-passed tax on oil "windfall profits" that Carter proposed and the Senate will take up today, Kennedy was attacking the president in Iowa for breaking his word on energy issues and for what the Massachusetts senator called "surrender to the oil companies and to OPEC."

Kennedy was particularly critical of Carter's decision earlier this year to remove federal price controls from oil -- the action that is producing the "windfall" that Carter's tax is designed to recapture in part. Kennedy, who favors reimposition of controls, called Carter's decision "the single action that contributes more to inflation than anything," and claimed that, in the 1976 campaign in Iowa, Carter had promised to preserve oil price controls.

For carter, the twin attacks could turn out to be a political plus, in the sense that they may neutralize each other and leave him looking like a moderate man in the middle.

Swearingen noted that Carter had declared his original energy plan in 1977 to be "the moral equivalent of was." but "in my opinion the banner he carries into battle is not that of a righteous crusade but rather the tattered rag of political expediency," the businessman said in his address. Carter's goal, Swearingen said, was "to smear the oil business and divert public attention from the flaws in Carter's own program."

"He knows full well that the entire profit per gallon of products sold by the oil industry amounts to only three or four cents," Swearingen said. "he knows full well that his [windfall] proposal is an excise tax -- truly a sales tax -- that will be paid by the public."

He derided Carter as a president whose popularity "has shrunk to the point where it scarcely exceeds the prime [interest] rate," and accused Carter of "desperately searching for scapegoats and in the process misleading the . . . public."

Kennedy, meanwhile, laid out six facets of energy policy in which he said he and Carter have "sharp differences."

During a day-long motorcade through the flat, open farmlands of eastern Iowa, Kennedy quoted Carter's own campaign statements here in 1976 -- in which Carter promised to oppose deregulation of oil and natural gas prices.

Once in the White House, Carter took the opposite position -- a switch that Kennedy summed up this way: "the moral equivalent of war has become the practical equivalent of surrender to the oil companies and to OPEC."

"The single action that contributes more to inflation than anything," Kennedy said, "is the single action that President Carter said he would not take, here in Iowa in 1976 -- the decontrol of petroleum prices.

Kennedy took the pokes at the president before an audience of Grinnell College students, whose cheering rolled down from the bleachers and echoed throughout the school's ancient gym.

Kennedy's pointed comparison of candidate Carter's speeches and President Carter's actions drew a fairly warm response from the audience, but the senator drew the loudest cheers when he pointed out that, unlike Carter, he thinks licensing of nuclear power plants should be stopped for at least two years.

Since he opened his campaign a week ago, Kennedy's stump speeches have been marred by mangled syntax, mistakes and minor slips of the tongue. In Des Moines Monday, he said he wanted the help of "every fam farmily" in Iowa. And he called for government aid for the "wabash Railroad." there is no such railroad. (Kennedy, laughing at his flub, said today he meant the Rock Island.)

But at Grinnell today he put everything together -- a tough speech, excellent delivery and an enthusiastic crowd, giving him the kind of campaign moment that candidates must dream about.

In addition to price controls and nuclear power, Kennedy said he differs with Carter on the "windfall profits" tax, conservation, national security aspects of the energy issue and the oil companies' right to buy competing forms of energy.

Kennedy said the president has given in to oil industry pressure on the profits tax because "he wants a tax, for the sake of a legislative victory." He said Carter should fight harder for a tax that will recapture at least half of the extra profit the firms will realize because of price decontrol.

Kennedy said Carter's emphasis on developing synthetic fuels amounts to "a spree of wasteful spending." He said the government should test the synfuel concept before committing the billions Carter has asked for, and he said energy conservation could provide greater benefits more cheaply.

On what he called "national security" questions, Kennedy said Carter had bungled negotiations with Mexico on petroleum purchases and had failed to build up a useful strategic petroleum reserve.

On the sixth point, Kennedy noted that Carter had promised in Iowa in 1976 that he would support "legal prohibitions against ownership of competing types of energy." Since then, Kennedy said. "The president has not proposed a single measure to carry out this promise."

Kennedy closed his speech with another quotation from candidate Carter four years ago.

Kennedy noted that Carter criticized then-President Gerald Ford for allowing a "sudden increase in the price of oil . . . letting the average American pay for the politicians' mistakes."

Then Kennedy took his final jab at the president: "His criticism of Gerald Ford then has become the epitaph for his own energy policy now."