To have a successful sublease you need a good lease agreement and a good subtenant. And you may need some luck on top of that.
You should use a professionally drafted lease, not one you make up yourself. It's far too easy to make mistakes, to include unlawful or unenforceable clauses, and otherwise create trouble for yourself if you draft your own lease.
If you have a subtenant, you obtain a security deposit from your tenant and return it to your tenant, and are expected to fully comply with landlord-tenant law in relation to the deposit.
If you do not want to return to the unit after the end of the subtenancy, you may want to ask your landlord if he'll release you and accept the proposed subtenant as a replacement tenant, such that you're out of the middle.

