A federal judge in Billings, Mont., yesterday upheld the authority of Congress to declare the Bob Marshall Wilderness Area in Montana off limits to oil and gas drilling, but said only Interior Secretary James G. Watt could set the duration of such a ban.

"It's one of those decisions where it's a little hard to figure out who's won and who's lost," said James Goetz, attorney for two conservation groups trying to protect the 1.5 million-acre wilderness area from mineral exploration.

The House Interior Committee invited confrontation with Watt in May when it relied on a little-used provision of the 1976 Federal Land Policy Management Act to force him to establish an emergency ban on any exploration leases in the Bob Marshall area until January 1, 1984, at which time a permanent ban is to go into effect.

The action was in response to fears of environmentalists that some of the more than 340 applications for drilling leases in the area were about to be approved.

Watt reluctantly ordered the ban, but his former employers, the Mountain States Legal Foundation, challenged it in court.

The ruling yesterday by U.S. District Court Judge William Jameson upholds the constitutionality of the ban, but orders Watt to revoke it and reissue one with a "scope and duration" of his choosing.