You are quite correct that you have made ineligible contributions to your IRAs for 2016 as well as 2017.
The 2017 contribution is easy to fix: just withdraw the contribution (and all earnings from it) by Tax Day in mid-April 2018. If you like, you can withdraw only what you need to: $5500 minus your taxable compensation for 2017 where compensation means things like wages or salary, self-employment income, commissions on sales, etc -- any payment for work of some kind -- but not inheritances, even if being a loving grandchild to a crotchety grandpa was hard work. This withdrawal can be done by writing to the IRA custodian and simply saying that you have changed your mind and have decided that you want to contribute only $X to your IRA for 2017, and would they please return the $5500 minus $X and all the earnings on the amount being returned. If you do this in timely fashion (don't send the request on April 15, 2018! postmarks count with the IRS, not with IRA custodians), there is no harm and no foul. Note that the earnings part of the withdrawal is taxable income to you.
The 2016 contribution requires more work and payment of fines and excise taxes. Once again, you need to write to the IRA custodian explaining that you have over-contributed to your IRA for 2016 and wish to withdraw the excess and all earnings thereon so as to regularize your situation. Do this as soon as possible. There may be mandatory withholding of tax from the money distributed to you.