Retirement tax questions

Thank you! 

Hypothetically, if I made $4000 worth of deductible contributions to my traditional over a span of 4 years, and had gains of $2000 during that time, and wanted to do a Roth conversion of the entire amount today, would I pay capital gains tax on $2000 and federal and state income tax on $4000? 

On a different note, is it possible to do nondeductible contributions to a TSP account?