AOTC usage / 529 overage

My sons are both in college, and since our income is low, we should not owe any income tax this year. Therefore the AOTC $2500 credit is more than we can use. Additionally, we'd like to take as much as possible from the 529 plan so we don't leave any excess behind. What's the best way to do this given:

1. $5,742 in expenses for year

2. No anticipated tax due

3. $15K in 529 plan

 

Can we take $4,724 from 529 plan and use only $1,000 of the AOTC? Or do you have to use $4,000 for AOTC (getting the $1,000 refund) and then take only $1,742 from the 529 plan? 

 

Appreciate any clarification or guidance.