Mansfield Town legend Matt Green has retired from professional football at the age of 39.