Although it has posted losses in three of the past four years and was in the red for the first quarter of this year, the Federal National Mortgage Association expects to show a profit for 1985, Chairman David O. Maxwell said yesterday.

"This year, I am pleased to say we have a good chance to earn a profit," Maxwell told shareholders at the annual stockholders meeting here.

The company could be in the black as early as this quarter, he said after the meeting.

Maxwell attributed his optimism to the current strong real estate market and to lower interest rates. His company buys mortgages from lenders and then either holds them or sells mortgage-backed securities based on them. It derives fees for its services, and an active market boosts that income.

Fannie Mae's difficulties stem primarily from its large portfolio of old, low-interest loans, which yield less than the cost of the money the company must borrow to finance them. Thus, a decline in interest rates reduces this "negative spread." In addition, much of the high-cost debt that Fannie Mae issued three to five years ago is maturing, and the company is able to roll it over into less-expensive notes.

"Volumes are very good, margins are good, commitment fees are holding up well, are improving in fact, mortgage-backed security fees are up, and interest rates are down. We're turning over higher-cost debt with lower-cost debt," Maxwell said.

Fannie Mae officials said the company is rolling over some $33.7 billion in debt this year. About half of that is already done, they said, adding that on the portion rolled over in the first quarter the average rate declined to 10.49 percent from 11.75 percent.

Maxwell said the company is doing well on its new investment -- mortgages purchased and held. He said that this business generates not only fees but also income from the "spread" between the yield on the mortgages and the cost of the debt financing them. He added that the company is making every effort to match maturities of its debt -- even at the expense of forgoing some short-term advantage -- with the anticipated lives of these mortgages.

New business netted Fannie Mae $89 million last year, he said.

Likewise, the company's mortgage-backed securities are doing well, with a 1984 net of $52 million, Maxwell said.

The portfolio of old loans remains "the corporation's problem child . . . , a 'block of granite' . . . that almost sank the ship in the early '80s," he said. But he added that the corporation has managed to narrow both the negative spread and the gap between the maturity of these loans and the debt financing them.

Maxwell also challenged a recent report by the General Accounting Office that viewed with alarm the risk that Fannie Mae's huge debt poses for the federal government. Fannie Mae is a congressionally chartered corporation, and its ties to the government have allowed it to borrow more cheaply because creditors assume that the government would make sure its debts were paid.

GAO, an agency of Congress, recommended increased government oversight. Maxwell called current oversight by the Treasury and the Department of Housing and Urban Development "tough and demanding." And as to the risk, he said in apparent reference to such things as the bailout of Continental Illinois Bank, "I fail to see how Fannie Mae's risk to the government differs from any other large financial institution in this country. Does anyone have any lingering doubt that the government cannot let large financial institutions go under?"