Hate to be the bearer of bad news, but nearly all employers have the legal upper hand in code produced while you are working in the capacity of an employee when it comes to "intellectual property." This is for two reasons. The first is that most companies have you sign an employee agreement expressly stating that anything you create while an employee, period, is theirs. Secondly, an employee status is regarded by the law as a work-for-hire status anyway, which implies the same rights of the employer.
For certain, the argument "because you aren't being paid to write the code, you own the code" will not hold water whatsoever. Reason being, if you were on company time and/or using company equipment and/or developing code expressly used in company projects, it is nearly impossible to establish that "you weren't being paid to write the code." The only safe way to establish true autonomy in your ownership while employed whould be to write it truly on your own time with your own software and equipment, and then approach management with the idea for its us. Even if you do not want your employer to purchase it, an agreement would still be highly indicated which would state that they waive any right to the property and that it is being provided to them for use by you free of change. Anything else is very sticky.
I am not a lawyer but am a business owner in the software industry, in case you are wondering "how I know". Of course, it is always best to defer to an attorney for true legal counsel.
Hope that helps.