Density-functional theory using an optimized exchange-correlation potential