I'll show that
$\int {{\text{P}}(x){e^{ax}}dx} = e^{ax}\sum\limits_{k = 0}^n {{{\left( { - 1} \right)}^k}\frac 1 {a^{k+1}}\frac{{{d^k}}}{{d{x^k}}}\left( {{\text{P}}\left( x \right)} \right)} + C$
where $n=\deg P$
We start by
$\mathrm I(n)=\int x^n e^x dx$
Integration by parts will give you
$\int x^n e^x dx =x^n e^x-n\int x^{n-1}e^xdx$
that is
$\mathrm I(n)=x^ne^x-n\mathrm I(n-1)$
Induction gives:
${\text{I}}(n) = {x^n}{e^x} - n{x^{n - 1}}{e^x} + n\left( {n - 1} \right){x^{n - 2}}{e^x} + \cdots + {\left( { - 1} \right)^k}n\left( {n - 1} \right) \cdots \left( {n - k + 1} \right){x^{n - k}}{e^x} + {\left( { - 1} \right)^{k + 1}}n\left( {n - 1} \right) \cdots \left( {n - k} \right)I\left( {n - k - 1} \right)$
I guess you note that all but the last term is $e^x$ times $\dfrac{d^k}{dx^k}(x^n)$
We choose $k=n-1$ to get the following:
${\text{I}}(n) = {x^n}{e^x} + {\left( { - 1} \right)^1}\frac{d}{{dx}}\left( {{x^n}} \right){e^x} + \cdots + {\left( { - 1} \right)^{n - 1}}\frac{{{d^{n - 1}}}}{{d{x^{n - 1}}}}\left( {{x^n}} \right){e^x} + {\left( { - 1} \right)^n}n!I\left( 0 \right)$ ${\text{I}}(n) = {x^n}{e^x} + {\left( { - 1} \right)^1}\frac{d}{{dx}}\left( {{x^n}} \right){e^x} + \cdots + {\left( { - 1} \right)^{n - 1}}\frac{{{d^{n - 1}}}}{{d{x^{n - 1}}}}\left( {{x^n}} \right){e^x} + {\left( { - 1} \right)^n}n!{e^x} + C$
We can put that under a sum, more nicely: ${\text{I}}(n) = {e^x}\sum\limits_{k = 0}^n {{{\left( { - 1} \right)}^k}\frac{{{d^k}}}{{d{x^k}}}\left( {{x^n}} \right)} + C$
Surely, we can now think about $e^{ax}$. We have
$\eqalign{ & {\text{J}}(n) = \int {{x^n}{e^{ax}}dx} = \frac{1}{{{a^{n + 1}}}}\int {{{\left( {ax} \right)}^n}{e^{ax}}d\left( {ax} \right)} = \frac{1}{{{a^{n + 1}}}}\int {{u^n}{e^u}du} \cr & {\text{J}}(n) = \frac{1}{{{a^{n + 1}}}}{e^u}\sum\limits_{k = 0}^n {{{\left( { - 1} \right)}^k}\frac{{{d^k}}}{{d{u^k}}}\left( {{u^n}} \right)} + C \cr & {\text{J}}(n) = \frac{1}{{{a^{n + 1}}}}{e^{ax}}\sum\limits_{k = 0}^n {{{\left( { - 1} \right)}^k}\frac{{{d^k}}}{{d{{\left( {ax} \right)}^k}}}\left( {{a^n}{x^n}} \right)} + C \cr & {\text{J}}(n) = {e^{ax}}\sum\limits_{k = 0}^n {{{\left( { - 1} \right)}^k}\frac{1}{{{a^{k + 1}}}}\frac{{{d^k}}}{{d{x^k}}}\left( {{x^n}} \right)} + C \cr} $
Now that we have this, we can consider an arbitrary polinomial in $x$:
$\mathrm P(x)=p_nx^n+p_{n-1}x^{n-1}+\cdots+p_1x+p_0$
Since the polynomial is a linear comination of powers of $x$, and both the integral and the derivative are linear operators, we have
$\int {{\text{P}}(x){e^{ax}}dx} = {e^{ax}}\sum\limits_{k = 0}^n {{{\left( { - 1} \right)}^k}\frac{1}{{{a^{k + 1}}}}\frac{{{d^k}}}{{d{x^k}}}{\text{P}}\left( x \right)} + C $
Note the interesting result. The operator
$\mathrm I = \int {\left( \text{ } \cdot \text{ } \right){e^{ax}}dx} $
is equivalent to the operator
${\text{D}} = {e^{ax}}\sum\limits_{k = 0}^n {{{\left( { - 1} \right)}^k}\frac{1}{{{a^{k + 1}}}}\frac{{{d^k}}}{{d{x^k}}}\left( {{\text{ }}\cdot{\text{ }}} \right)} $
for a polynomial $\mathrm P(x)$ where $n=\deg P$
To evaluate $\int {P\left( x \right)\sin bxdx} $ and $\int {P\left( x \right)\cos xdx} $
recall the last result:
$\int {P\left( x \right){e^{ax}}dx} = {e^{ax}}\sum\limits_{k = 0}^n {{{\left( { - 1} \right)}^k}\frac{1}{{{a^{k + 1}}}}\frac{{{d^k}}}{{d{x^k}}}{\text{P}}\left( x \right)} $
and Euler's Formula:
${e^{ibx}} = \cos bx + i\sin bx$
Then let $a=bi$ and get
$\int {P\left( x \right){e^{ax}}dx} = {e^{bix}}\sum\limits_{k = 0}^n {{{\left( { - 1} \right)}^k}\frac{1}{{{{\left( {ib} \right)}^{k + 1}}}}\frac{{{d^k}}}{{d{x^k}}}{\text{P}}\left( x \right)} = - {e^{bix}}\sum\limits_{k = 0}^n {\frac{{{i^{k + 1}}}}{{{b^{k + 1}}}}\frac{{{d^k}}}{{d{x^k}}}{\text{P}}\left( x \right)} $
We only need to address the powers of $i$. We need to split
$\sum\limits_{k = 0}^n {\frac{{{i^k}}}{{{b^{k + 1}}}}\frac{{{d^k}}}{{d{x^k}}}{\text{P}}\left( x \right)} $
into its real and imaginary parts. Assume that $n=2m$ (ie the polynomial is of even degree). We can write
$\sum\limits_{k = 0}^n {\frac{{{i^k}}}{{{b^{k + 1}}}}\frac{{{d^k}}}{{d{x^k}}}{\text{P}}\left( x \right)} = \sum\limits_{k = 0}^m {\frac{{{i^{2k}}}}{{{b^{2k + 1}}}}\frac{{{d^{2k}}}}{{d{x^{2k}}}}{\text{P}}\left( x \right)} + \sum\limits_{k = 0}^{m - 1} {\frac{{{i^{2k + 1}}}}{{{b^{2k + 2}}}}\frac{{{d^{2k + 1}}}}{{d{x^{2k + 1}}}}{\text{P}}\left( x \right)} $
$\sum\limits_{k = 0}^n {\frac{{{i^k}}}{{{b^{k + 1}}}}\frac{{{d^k}}}{{d{x^k}}}{\text{P}}\left( x \right)} = \sum\limits_{k = 0}^m {\frac{{{{\left( { - 1} \right)}^k}}}{{{b^{2k + 1}}}}\frac{{{d^{2k}}}}{{d{x^{2k}}}}{\text{P}}\left( x \right)} + i\sum\limits_{k = 0}^{m - 1} {\frac{{{{\left( { - 1} \right)}^k}}}{{{b^{2k + 2}}}}\frac{{{d^{2k + 1}}}}{{d{x^{2k + 1}}}}{\text{P}}\left( x \right)} $
This gives
$\eqalign{ & \int {P\left( x \right)\sin bxdx} = \left( {\sin bx - \cos bx} \right)\sum\limits_{k = 0}^{m - 1} {\frac{{{{\left( { - 1} \right)}^k}}}{{{b^{2k + 2}}}}\frac{{{d^{2k + 1}}}}{{d{x^{2k + 1}}}}{\text{P}}\left( x \right)} \cr & \int {P\left( x \right)\cos bxdx} = \left( {\sin bx - \cos bx} \right)\sum\limits_{k = 0}^m {\frac{{{{\left( { - 1} \right)}^k}}}{{{b^{2k + 1}}}}\frac{{{d^{2k}}}}{{d{x^{2k}}}}{\text{P}}\left( x \right)} \cr} $
If $n = 2m + 1$ we'd get
$\eqalign{ & \int {P\left( x \right)\sin bxdx} = \left( {\sin bx - \cos bx} \right)\sum\limits_{k = 0}^m {\frac{{{{\left( { - 1} \right)}^k}}}{{{b^{2k + 2}}}}\frac{{{d^{2k + 1}}}}{{d{x^{2k + 1}}}}{\text{P}}\left( x \right)} \cr & \int {P\left( x \right)\cos bxdx} = \left( {\sin bx - \cos bx} \right)\sum\limits_{k = 0}^m {\frac{{{{\left( { - 1} \right)}^k}}}{{{b^{2k + 1}}}}\frac{{{d^{2k}}}}{{d{x^{2k}}}}{\text{P}}\left( x \right)} \cr} $