I’m assuming that you’re a R user and already know about the forecast package.
So the simplest way is to perform the auto.arima on your TS (time-series object made using ts() from forecast package) object and then run $coef . This will give you the coefficients based on system selected ARIMA order (p,d,q).
You can perform the same steps with ARMA model as well and get your coefficients.
Let me know if this solves your problem.