Check Sandbox or Production Org using Apex

SELECT Id, IsSandbox, Name FROM Organization LIMIT 1

If IsSandbox is true, the it is Sandbox Org else it is Production Org.